动画UIViews使交叉淡化效果不能很好地工作

Hur*_*rkS 4 iphone animation uiview ios uideviceorientation

我已经成功创建了一个从tabBar选择中显示的图标菜单.您可以在纵向或横向中查看此菜单.

由于屏幕上的空间,我已经制作了它,所以在纵向中你可以查看4x4图标..但是由于在横向观看时的尺寸这个剂量效果不好...所以我做了它,这样你就可以看到2行由于这个原因,我决定为菜单创建两个UIViews,当设备旋转时我在两个视图之间切换.

即如果纵向电流和设备旋转负载横向和卸载纵向,反之亦然.

这是我用来更改设备旋转视图的代码,这非常好用(可能不是最好的代码,但它是我能做的最好的代码)

if  ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait)
        {
            if([jumpBarContainerLandscape superview])
            {
            // Device is changing from landscape to protrait change views to fit
            // load landscape view
            jumpBarContainerPortrait = [[UIView alloc] initWithFrame:CGRectMake(0.0, (367 - jumpBarHeightPortrait), 320.0, (jumpBarHeightPortrait + 49.0))];
            jumpBarContainerPortrait.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
            jumpBarContainerPortrait.alpha = 0.0;

            // add jumpbar container to view
            [self.view insertSubview:jumpBarContainerPortrait belowSubview:actionTabBar];

            [UIView animateWithDuration:0.2
                                  delay:0.0f
                                options:UIViewAnimationCurveEaseIn 
                             animations:^{

                                 jumpBarContainerLandscape.alpha = 0.0;


                             } completion:^(BOOL finished) {
                                 if (finished) {


                                 }
                             }];


            [UIView animateWithDuration:0.2
                                  delay:0.0f
                                options:UIViewAnimationCurveEaseIn 
                             animations:^{

                                 jumpBarContainerPortrait.alpha = 1.0;


                             } completion:^(BOOL finished) {
                                 if (finished) {

                                     // remove subView for superView
                                     [jumpBarContainerLandscape removeFromSuperview];
                                 }
                             }];

            }
        }
        else if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight)
        {
            if ([jumpBarContainerPortrait superview])
            {
            // Device is changing from portrait to landscape change views to fit
            // load landscape view
            jumpBarContainerLandscape = [[UIView alloc] initWithFrame:CGRectMake(0.0, (207 - jumpBarHeightLandscape), 480.0,  (jumpBarHeightLandscape + 49.0))];
            jumpBarContainerLandscape.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
            jumpBarContainerLandscape.alpha = 0.0;

            // add jumpbar container to view
            [self.view insertSubview:jumpBarContainerLandscape belowSubview:actionTabBar];


                // fade out
            [UIView animateWithDuration:0.2
                                  delay:0.0f
                                options:UIViewAnimationCurveEaseIn 
                             animations:^{

                                 jumpBarContainerPortrait.alpha = 0.0;


                             } completion:^(BOOL finished) {
                                 if (finished) {


                                 }
                             }];

               // fade in
            [UIView animateWithDuration:0.2
                                  delay:0.0f
                                options:UIViewAnimationCurveEaseIn 
                             animations:^{


                                 jumpBarContainerLandscape.alpha = 1.0;


                             } completion:^(BOOL finished) {
                                 if (finished) {

                                     // remove subView for superView
                                     [jumpBarContainerPortrait removeFromSuperview];
                                 }
                             }];
            }
        }
Run Code Online (Sandbox Code Playgroud)

现在我遇到的问题是两个UIViews之间的动画非常难看,它不是很流畅,你可以看到动画等两个不同的视图,这是不可取的..我想知道是否有人能想到一个很好的方式两者之间的交叉淡入淡出让它看起来更顺畅......

任何帮助将不胜感激.

编辑:

所以我刚刚尝试创建一个CATransaction,但是我在一行上有一个错误给我这个错误没有可见的@interface为'UIView'声明了选择器'jumpBarContainerPortrait' 我在下面的行中添加了一个注释我得到了这个错误.. 任何帮助,将不胜感激

[CATransaction begin];
            CATransition *animation = [CATransition animation];
            animation.type = kCATransitionFade;
            animation.duration = 3.50;

            [self.view insertSubview:jumpBarContainerPortrait belowSubview:actionTabBar];

            [[self.view jumpBarContainerPortrait] addAnimation:animation forKey:@"Fade"]; // Error is happening here!
            [CATransaction commit];
Run Code Online (Sandbox Code Playgroud)

Jay*_*sky 7

不使用单独的淡入和淡出动画,而是使用UIView方法"transitionFromView".这是一个例子:

        [UIView transitionFromView:jumpBarContainerLandscape
                            toView:jumpBarContainerPortrait
                          duration:crossDissolveTime 
                           options:UIViewAnimationOptionTransitionCrossDissolve 
                        completion:NULL];
Run Code Online (Sandbox Code Playgroud)

  • 大。如果可以,请“接受”我的回答。 (2认同)