4

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

由于屏幕上的空间,我已经制作了它,以便在纵向中您可以查看 4x4 图标..但是由于在横向查看时的大小,这不能很好地工作..所以我做了它以便您可以查看 2 行6 和 1 行 4。因此,我决定为菜单创建两个 UIView,当设备旋转时,我在两个视图之间切换。

即如果纵向当前和设备旋转加载横向和卸载纵向,反之亦然。

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

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

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

任何帮助将不胜感激。

编辑:

所以我刚刚尝试创建一个 CATransaction,但是我在一行上有一个错误,给了我这个错误没有可见的 @interface for '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];
4

1 回答 1

7

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

        [UIView transitionFromView:jumpBarContainerLandscape
                            toView:jumpBarContainerPortrait
                          duration:crossDissolveTime 
                           options:UIViewAnimationOptionTransitionCrossDissolve 
                        completion:NULL];
于 2012-06-22T00:50:11.497 回答