Here is my best effor to learn about NSScrollView:In a macOS App: change viewDidLoad() to setup, add a scrollView to the storyboard, and run to show a Scrolling view?: override func viewDidLoad() { super.viewDidLoad()//Create a Big documentView and fill with array of NSButtons? let myDocView = NSView(frame: NSRect(x: 0, y: 0, width: 2000, height: 2000)) let ymax = Int(myDocView.frame.size.height) for row in 1...9 { for col in 1...9 { let aButton = NSButton(frame: NSRect(x: col * 44 + 10, y: ymax - (row * 44 + 10), width: 32, height: 37)) aButton.title = row.description + "/" + col.description myDocView.addSubview(aButton) } }//then find the NSScrollView added into the View in the storyboard with?: let arrayOfViews = self.view.subviews print("arrayviews is \(arrayOfViews)") let mySV = arrayOfViews[0] as! NSScrollView print("ScrollView is \(mySV)") mySV.scrollerStyle = .overlay mySV.hasVerticalScroller = true mySV.hasHorizontalScroller = true mySV.autohidesScrollers = false//then add my documentView? mySV.documentView = myDocView }I am at a loss for understanding and any help here is appreciated
Post
Replies
Boosts
Views
Activity
I did use IB?(storyboard) to create a NSScrollView and use the code below to find the view as I usually assign a tag number to views but with NSScrollview I am unable to assign a tag number: let arrayOfViews = self.view.subviews print("arrayviews is \(arrayOfViews)") let mySV = arrayOfViews[0] as! NSScrollView print("ScrollView is \(mySV)")Do I create a Scroll view using only IB? Does it have anything to do with the constraints; I removed most of the constraints and observed no scroll bars.
This code below worked once I changed my storyboard; I removed most of the constraints on the views and resized the Scrollview to be much smaller then the main view. ran the app and it started working. I dont know how or understand why.class ViewController: NSViewController { override func viewDidLoad() { super.viewDidLoad() let myDocView = NSView(frame: NSRect(x: 0, y: 0, width: 2000, height: 2000)) let ymax = Int(myDocView.frame.size.height) for row in 1...9 { for col in 1...9 { let aButton = NSButton(frame: NSRect(x: col * 44 + 10, y: ymax - (row * 44 + 10), width: 32, height: 37)) aButton.title = row.description + "/" + col.description myDocView.addSubview(aButton) } } self.view.addSubview(myDocView) let aButton = NSButton(frame: NSRect(x: 20, y: 20, width: 32, height: 37)) aButton.title = "aa" self.view.addSubview(aButton) let arrayOfViews = self.view.subviews print("arrayviews is \(arrayOfViews)") let mySV = arrayOfViews[0] as! NSScrollView print("ScrollView is \(mySV)") mySV.scrollerStyle = .overlay mySV.hasVerticalScroller = true mySV.hasHorizontalScroller = true mySV.autohidesScrollers = false mySV.documentView = myDocView aButton.title = "BB" mySV.addSubview(aButton) }
Here is a simplified code for viewDidLoad(): override func viewDidLoad() { super.viewDidLoad() let myDocView = NSView(frame: NSRect(x: 0, y: 0, width: 2000, height: 2000)) let ymax = Int(myDocView.frame.size.height) for row in 1...9 { for col in 1...9 { let aButton = NSButton(frame: NSRect(x: col * 44 + 10, y: ymax - (row * 44 + 10), width: 32, height: 37)) aButton.title = row.description + "/" + col.description myDocView.addSubview(aButton) } } let arrayOfViews = self.view.subviews print("arrayviews is \(arrayOfViews)") let mySV = arrayOfViews[0] as! NSScrollView print("ScrollView is \(mySV)") mySV.scrollerStyle = .overlay mySV.hasVerticalScroller = true mySV.hasHorizontalScroller = true mySV.autohidesScrollers = false mySV.documentView = myDocView }Drag an NSScrollView from the library into the view in the storyboard and play with the constraints and view size.I played with the constraints and size of the NSScrollView and found that I can add back all constraints and expand the Scrolll view to fill the main view. It will work; I don't understand how.
Thank you for your considerations. I learned that three things are neseccary for a NSScrollView which are not documented clearly and there is absolutely no sample code anywhere I could find.1) There needs to be another bigger NSView that hold the total display.2) That a NSScrollView need to be added to the storyboard and the some how defined without using tag numbers.(I used view.subviews)3) That the NSView need to be added to the NSScrollView using ScrollView.documentView = NSView(in 1)I read the links you provided.
Thank you for your response; I am grateful and learned something new today.
Whoa! that is simply amazing to me!!. I am searching but would have much difficulty finding your response. Big thanks. I will study it. Your response needs to be in the Quick Help guide built in to Xcode. But Quick Help offers some little help instead.
I also found in Swift UIkit the variable
static var isVoiceOverRunning: Bool {get}
but first try at coding it failed so more study is in order.
Found it!. But the explanation is not so tricky. Simply put the answer is Yes in SwiftUI to directly detect if voice over is on use:
if UIAccessibility.isVoiceOverRunning {}
I tried this to find it and read another post from @OOPer, Thanks
1) if isVoiceOverRunning {}. not in scope error
2) if Accessibility.isVoiceOverRunning {}. Accessibility has no member "isVoiceOverRunning"
3) if UIAccessibility.isVoiceOverRunning().
Sweet success. I re-discovered it. Yeepee. 😀
I was missing the UI of UIAccessibility. and Quick help was not helping me and @OOPer did.
Same, Swift Playground crashes for no reason. I am coding Android Studio apps now.