如果在animator()处使用了selectedIndex,则autoresizingMask无效。
如果您不使用animator(),那就很好。
无法使用animator()手动执行selectedIndex。
请告诉我你是否知道。
self.animator()。selectedIndex = 2
self.selectedIndex = 2
资源
let array = ["page 1", "page 2", "page 3", "page 4", "page 5", "page 6"]
class PageController: NSPageController, NSPageControllerDelegate {
@IBAction func moveThreePage(_ sender: Any) {
// NG
self.animator().selectedIndex = 2
// OK
//self.selectedIndex = 2
}
override func viewDidLoad() {
super.viewDidLoad()
self.delegate = self
self.arrangedObjects = array
}
func pageController(_ pageController: NSPageController, viewControllerForIdentifier identifier: String) -> NSViewController {
let vc = self.storyboard!.instantiateController(withIdentifier: "ViewController") as! ViewController
vc.view.autoresizingMask = [.height, .width]
return vc
}
func pageController(_ pageController: NSPageController, identifierFor object: Any) -> String {
return "ViewController"
}
func pageController(_ pageController: NSPageController, prepare viewController: NSViewController, with object: Any?) {
guard let item = object as? String,
let itemVC = viewController as? ViewController else {
return
}
itemVC.item = item
}
func pageControllerDidEndLiveTransition(_ pageController: NSPageController) {
self.completeTransition()
}
}
最佳答案
谢谢。它完成了。
@IBAction func moveThreePage(_ sender: Any) {
//To animate a selectedIndex change:
NSAnimationContext.runAnimationGroup({ context in
self.animator().selectedIndex = 2
}, completionHandler: {
self.completeTransition()
})
}
关于swift - NSPageController,如果在animator()上使用了selectedIndex,则autoresizingMask无效,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60144454/