如何使整个应用程序的背景相同。而不是使用一些动画(推,弹,翻转等)去另一个ViewController
。 我想用一些动画更改前景视图。还有下一个视图应该在另一个ViewController中
例如,让两个彩色屏幕为UIViews。单击第一个视图上的按钮我想移动view1幻灯片view2。
Anyway the background need to remain unchanged Note: With different view controllers
答案 0 :(得分:0)
试试这段代码:
- (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];
}
使用这个简单的代码,我在屏幕内移动(btnEnter
)myView
(在屏幕外显示)带动画,(btnExit
)移出另一个动画
你可以使用很多动画,我选择了一个。
请务必在班级定义中添加CAAnimationDelegate
。
背景总是一样的。 (UIViewController' s)
答案 1 :(得分:0)
您可以更改动画持续时间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)];
}];