码迷,mamicode.com
首页 > 移动开发 > 详细

IOS开发 - Create Push Segue Animation Without UINavigationController

时间:2014-08-01 13:04:11      阅读:315      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   使用   os   strong   

APPLE提供了三种storyboard segue的方式:push,modal,custom .

push segue是系统预定义的跳转方式,

bubuko.com,布布扣

为了使其能正常工作,我们还必须加载UINavigationController。

有时候,我们不想看到UINavigation bar,我们可以使用modal segue。

modal segue 的跳转方式有四种:Cover Vertical, Flip Horizontal, Cross Dissolve and Partial Curl。

要是我们想要的跳转方式与这四种方式都不同,我们可以使用自定义跳转方式custom segue。

下面是一个实现custom segue的样例:

1.创建一个UIStoryboardsegue的子类

bubuko.com,布布扣

2.重载-(void)perform 方法

 1 - (void) perform
 2 {
 3     UIViewController *desViewController = (UIViewController *)self.destinationViewController;
 4     
 5     UIView *srcView = [(UIViewController *)self.sourceViewController view];
 6     UIView *desView = [desViewController view];
 7     
 8     desView.transform = srcView.transform;
 9     desView.bounds = srcView.bounds;
10     
11     if(isLandscapeOrientation)
12     {
13         if(isDismiss)
14         {
15             desView.center = CGPointMake(srcView.center.x, srcView.center.y  - srcView.frame.size.height);
16         }
17         else
18         {
19             desView.center = CGPointMake(srcView.center.x, srcView.center.y  + srcView.frame.size.height);
20         }
21     }
22     else
23     {
24         if(isDismiss)
25         {
26             desView.center = CGPointMake(srcView.center.x - srcView.frame.size.width, srcView.center.y);
27         }
28         else
29         {
30             desView.center = CGPointMake(srcView.center.x + srcView.frame.size.width, srcView.center.y);
31         }
32     }
33     
34     
35     UIWindow *mainWindow = [[UIApplication sharedApplication].windows objectAtIndex:0];
36     [mainWindow addSubview:desView];
37     
38     // slide newView over oldView, then remove oldView
39     [UIView animateWithDuration:0.3
40                      animations:^{
41                          desView.center = CGPointMake(srcView.center.x, srcView.center.y);
42                          
43                          if(isLandscapeOrientation)
44                          {
45                              if(isDismiss)
46                              {
47                                  srcView.center = CGPointMake(srcView.center.x, srcView.center.y + srcView.frame.size.height);
48                              }
49                              else
50                              {
51                                  srcView.center = CGPointMake(srcView.center.x, srcView.center.y - srcView.frame.size.height);
52                              }
53                          }
54                          else
55                          {
56                              if(isDismiss)
57                              {
58                                  srcView.center = CGPointMake(srcView.center.x + srcView.frame.size.width, srcView.center.y);
59                              }
60                              else
61                              {
62                                  srcView.center = CGPointMake(srcView.center.x - srcView.frame.size.width, srcView.center.y);
63                              }
64                          }
65                      }
66                      completion:^(BOOL finished){
67                          //[desView removeFromSuperview];
68                          [self.sourceViewController presentModalViewController:desViewController animated:NO];
69                      }];

70 } 

 

在viewcontroller中,重载prepareforsegue方法

 1 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
 2 {
 3     HorizontalSlideSegue *s = (HorizontalSlideSegue *)segue;
 4     s.isDismiss = NO;
 5     
 6     if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
 7     {
 8         s.isLandscapeOrientation = YES;
 9     }
10     else
11     {
12         s.isLandscapeOrientation = NO;
13     }

14 } 

3.选择custom segue 设置segue class为:customsegue(我们自定义的类)

bubuko.com,布布扣

4.使用代码方式调用segue: 

bubuko.com,布布扣

IOS开发 - Create Push Segue Animation Without UINavigationController,布布扣,bubuko.com

IOS开发 - Create Push Segue Animation Without UINavigationController

标签:des   style   blog   http   color   使用   os   strong   

原文地址:http://www.cnblogs.com/ZJUT-jiangnan/p/3884457.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!