我正在尝试更新我的willAnimateRotationToInterfaceOrientation代码,以将新的viewWillTransitionToSize用作IOS 9的一部分。
在我的应用程序中,我有两个完全独立的景观和肖像视图(它们的布局不同,采用不同的模式)。
在旋转期间,viewcontroller的self.view被分配到正确的视图(横向或纵向)。在IOS 9中使用viewWillTransitionToSize,这揭示了旋转动画和self.view赋值之间的时间竞争条件。
self.view = portraitView或self.view = landscapeView的分配可能发生在旋转之前,也可能发生在旋转之后。看来,因为视图赋值不是“动画”属性,它在animateWithDuration窗口期间的任何时间执行。
如何在旋转动画之前强制进行视图分配?
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id <UIViewControllerTransitionCoordinator>)coordinator
{
UIInterfaceOrientation oldOrientation = [[UIApplication sharedApplication] statusBarOrientation];
UIInterfaceOrientation orientation = [Utilities orientationByTransforming:[coordinator targetTransform] fromOrientation:oldOrientation];
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context)
{
[UIView animateWithDuration:[context transitionDuration] animations:^{
if (UIInterfaceOrientationIsLandscape(orientation)) {
self.view = self.landscapeView;
}
else{
self.view = self.portraitView;
}
} completion:^(BOOL finished){
//no completion logic for animateWithDuration
}];
} completion:^(id<UIViewControllerTransitionCoordinatorContext> context)
{
//no completion logic for animateAlongsideTransition
}];
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}
答案 0 :(得分:0)
我认为你需要提供两种观点:
[self.view addSubview: self.landscapeView];
[self.view addSubview: self.portraitView];
然后在他们之间褪色
self.landscapeView.alpha = self.portraitView.alpha = 0.0f;
[UIView animateWithDuration:[context transitionDuration] animations:^{
if (UIInterfaceOrientationIsLandscape(orientation)) {
self.landscapeView.alpha = 1.0f;
}
else{
self.portraitView.alpha = 1.0f;
}