我正在努力采用多任务来支持应用程序的拆分视图.但我发现app在右边时没有调用traitCollectionDidChange.有没有人对此有所了解?
你可以覆盖traitCollectionDidChange
你的ViewController
.
然而.
traitCollectionDidChange
从一种拆分视图模式更改为另一种模式时调用.例如从50/50视图到33/66.因此,当您进入多任务模式或退出时,不会调用它.
如果您需要处理所有事件,包括进入和退出多任务模式,请viewWillTransitionToSize:withTransitionCoordinator:
改用:
// put this in your ViewController code -(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator { [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; // TODO: put your code here (runs BEFORE transition complete) }
如果您希望您的代码称为AFTER,那么转换就可以了:
-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator { [coordinator animateAlongsideTransition:nil completion:^(id _Nonnull context) { // TODO: put your code here (runs AFTER transition complete) }]; }
你试过viewWillTransitionToSize方法吗?这用于通知容器其视图的大小即将更改.
Objective-C的
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator
迅速
func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) { coordinator.animateAlongsideTransition(nil, completion: { if UIDevice.currentDevice().orientation.isLandscape.boolValue { print("landscape") } else { print("portrait") } }