【问题标题】:How to slide two UIView's. Keeping the background unchanged如何滑动两个 UIView。保持背景不变
【发布时间】:2016-10-20 10:17:24
【问题描述】:

如何使整个应用程序的背景相同。而不是去另一个ViewController 有一些动画(推,弹出,翻滚等)。 我只想用一些动画改变前景视图。下一个视图应该在另一个 ViewController 中

例如让两个彩色屏幕成为 UIView。单击第一个视图上的按钮时,我想移动 view1 幻灯片 view2。

Anyway the background need to remain unchanged Note: With different view controllers

【问题讨论】:

标签: ios objective-c xcode


【解决方案1】:

试试这个代码:

- (IBAction)btnExit:(id)sender {
    [self setFrame:CGRectMake(-self.frame.size.width
                                 ,200
                                 ,self.frame.size.width
                                 , self.frame.size.height
                                 )];

    CATransition *animation = [CATransition animation];
    [animation setType:kCATransitionPush];
    [animation setSubtype:kCATransitionFromRight];
    [animation setDuration:.50];
    [animation setDelegate:self];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    CALayer *layer = [self layer];
    [layer addAnimation:animation forKey:nil];
}

- (IBAction)btnEnter:(id)sender {
    [self setFrame:CGRectMake(10
                                 ,200
                                 ,self.frame.size.width
                                 , self.frame.size.height
                                 )];

    CATransition *animation = [CATransition animation];
    [animation setType:kCATransitionPush];
    [animation setSubtype:kCATransitionFromLeft];
    [animation setDuration:.50];
    [animation setDelegate:self];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    CALayer *layer = [self layer];
    [layer addAnimation:animation forKey:nil];

}

通过这个简单的代码,我在屏幕内移动(使用btnEntermyView(开始时在屏幕外)使用动画,然后(btnExit)使用另一个动画移动。

你可以使用很多动画,我选择了一个。

记得在你的类定义中添加CAAnimationDelegate

背景总是一样的。 (UIViewController 的视图)

【讨论】:

    【解决方案2】:

    您可以更改动画持续时间 2

     [UIView animateWithDuration:1 animations:^{
                [view1 setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    
    
            }];
    
        [UIView animateWithDuration:1 animations:^{
                [view2 setFrame:CGRectMake( view1.frame.size.width,0, self.view.frame.size.width, self.view.frame.size.height)];
    
    
            }];
    

     [UIView animateWithDuration:1 animations:^{
                    [view2 setFrame:CGRectMake( view1.frame.size.width,0, self.view.frame.size.width, self.view.frame.size.height)];
    
             [view1 setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    
                }];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-19
      • 2019-08-12
      • 2014-01-09
      • 2013-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多