【问题标题】:switch between uivewconrollers with swipe gesture使用滑动手势在 uivewconrollers 之间切换
【发布时间】:2013-01-25 04:49:16
【问题描述】:

我正在尝试使用滑动手势(向上)和小动画在 4 V.C 之间切换,我正在使用 xib:

-(IBAction)gotonext:(UISwipeGestureRecognizer *)recognizer{
ibasar *ibas =[[ibasar alloc]initWithNibName:@"ibasar" bundle:nil];


[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];

[self.view addSubview:ibas.view];

[UIView commitAnimations];

  }

问题是,当我从第一个 V.C 切换到第二个时,完成了,但是当我从第二个切换到第三个时,应用程序停止了!尽管 switch 使用相同的代码! 任何帮助请..提前谢谢

【问题讨论】:

  • 结帐更新答案:)

标签: ios xcode gestures


【解决方案1】:

首先,如果要制作动画,请使用块动画。不是旧的动画方法。

其次,您只是在彼此之上添加子视图。这可能对内存很重。在动画结束时删除并丢弃旧视图,或者更好的是,使用 UINavigation 视图控制器为您处理所有这些。

【讨论】:

    【解决方案2】:

    您可以创建一个CATransition 动画。下面是一个示例,说明如何在将当前视图推出时将第二个视图(从左侧)滑入屏幕:

    UIView *theParentView = [self.view superview];
    
    CATransition *animation = [CATransition animation];
    [animation setDuration:0.3];
    [animation setType:kCATransitionPush];
    [animation setSubtype:kCATransitionFromLeft];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    
    [theParentView addSubview:yourSecondViewController.view];
    [self.view removeFromSuperview];
    
    [[theParentView layer] addAnimation:animation forKey:@"MainView"];
    

    【讨论】:

      猜你喜欢
      • 2013-05-06
      • 2011-04-17
      • 2013-06-23
      • 1970-01-01
      • 2014-10-20
      • 2017-08-18
      • 1970-01-01
      • 1970-01-01
      • 2014-09-24
      相关资源
      最近更新 更多