[英]Add Slide In from Left to Right animation(transition) in addSubView
I Try to imitate the NavigationViewController
, very similar to default MailApp
in iPhone
我试着模仿NavigationViewController
,非常类似于iPhone
默认MailApp
When clicking on a Mail summary, it should slide-in the mail details, and when BACK button is clicked, Mail Summary view is to be slided-in back again. 当邮件总结一下,应该滑入邮件的详细信息,并单击后退按钮时,邮件摘要视图被滑动式回来。
This is what I have to animate the transition from Summary To Detail ( removeFromSuperView
) 这就是我必须为从摘要到细节的过渡设置动画( removeFromSuperView
)
CGRect temp = self.view.frame;
temp.origin.x = 300;
[UIView animateWithDuration:0.5
delay:0.0
options: UIViewAnimationCurveEaseOut
animations:^{
self.view.frame = temp;
}completion:^(BOOL finished){
[self.view removeFromSuperview];
}];
This is what I have to animate the transition from Detail To Summary ( addSubview
) 这就是我必须动画从Detail to Summary( addSubview
)的过渡动画
CATransition *transition = [CATransition animation];
transition.duration = 0.5;
transition.type = kCATransitionFromRight;
transition.subtype = kCATransitionFade;
[parentView.layer addAnimation:transition forKey:nil];
[parentView addSubview:myVC.view];
Now, that My First part of code is working well! 现在,我的第一部分代码运行良好! Where-as the second part, I am just able to achieve the Fade-in animation. 在哪里 - 作为第二部分,我只能实现淡入动画。 How can I bring in the slide transition? 如何引入幻灯片过渡?
I just need to choose kCATransitionPush
type for my CATransition
我只需要为我的CATransition
选择kCATransitionPush
类型
CATransition *transition = [CATransition animation];
transition.duration = 0.5;
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
[transition setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[parentView.layer addAnimation:transition forKey:nil];
[parentView addSubview:myVC.view];
Update for Swift: Swift更新:
let transition = CATransition()
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromLeft
parentView.layer.add(transition, forKey: nil)
parentView.addSubview(myVC.view)
Or you could check out : HorizontalSlide Segue (just google it I cant get the link, on mobile) its a great sliding transition that is simply a segue that you add from view A to B.... 或者你可以看看:HorizontalSlide Segue(只是google它我无法获得链接,在移动设备上)它是一个很棒的滑动过渡,只是你从视图A到B添加的一个segue ....
On a side note, if this is in a nav controller, a push or a pop should have a slide animation by default... 另外,如果这是在导航控制器中,推送或弹出应默认具有幻灯片动画...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.