如何为两个视图之间的过渡设置动画,使其看起来第一个向上,第二个从底部出现?
Posted
技术标签:
【中文标题】如何为两个视图之间的过渡设置动画,使其看起来第一个向上,第二个从底部出现?【英文标题】:How to animate transition between two views so it look like the first is going up, and the second appears from bottom? 【发布时间】:2012-03-16 10:38:49 【问题描述】:我试过了,但它不起作用:
[UIView animateWithDuration:2.0
animations:^
[self.view addSubview:theSubView];
theSubView.frame=CGRectMake(self.view.frame.origin.x, 480, self.view.frame.size.width, self.view.frame.size.height);
self.view.transform=CGAffineTransformMakeTranslation(0, -480);
theSubView.transform=CGAffineTransformMakeTranslation(0, -480);
];
【问题讨论】:
【参考方案1】:试试这个:-
//首先创建一个CATransition对象来描述过渡
CATransition *transition = [CATransition animation];
// Animate over 3/4 of a second
transition.duration = 1;
// using the ease in/out timing function
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
// Now to set the type of transition. Since we need to choose at random, we'll setup a couple of arrays to help us.
NSString *types[4] = kCATransitionMoveIn, kCATransitionPush, kCATransitionReveal, kCATransitionFade;
NSString *subtypes[4] = kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom;
transition.type = types[1]; // choose ur type
transition.subtype = subtypes[2]; // choose ur type
// Finally, to avoid overlapping transitions we assign ourselves as the delegate for the animation and wait for the
// -animationDidStop:finished: message. When it comes in, we will flag that we are no longer transitioning.
transitioning = YES;
transition.delegate = self;
// Next add it to the containerView's layer. This will perform the transition based on how we change its contents.
[self.layer addAnimation:transition forKey:nil];
【讨论】:
以上是关于如何为两个视图之间的过渡设置动画,使其看起来第一个向上,第二个从底部出现?的主要内容,如果未能解决你的问题,请参考以下文章
如何为 Flutter SliverList 中的元素设置动画?