【问题标题】:how to animate first in a viewWillTransitionToSize using animateAlongsideTransition如何使用 animateAlongsideTransition 在 vi​​ewWillTransitionToSize 中首先设置动画
【发布时间】:2015-11-09 17:28:22
【问题描述】:

我正在尝试更新我的 willAnimateRotationToInterfaceOrientation 代码以使用新的 viewWillTransitionToSize 作为 IOS 9 的一部分。

在我的应用程序中,我有两个完全独立的横向和纵向视图(它们的布局不同,采用不同的模式)。

在旋转过程中,视图控制器的 self.view 被分配给正确的视图(横向或纵向)。在使用 viewWillTransitionToSize 的 IOS 9 中,这揭示了旋转动画和 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];
}

【问题讨论】:

    标签: ios objective-c ios9


    【解决方案1】:

    我认为您需要同时提供两种视图:

    [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;
             }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-03-19
      • 2014-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-21
      • 2012-04-29
      相关资源
      最近更新 更多