UIView的子视图的动画 [英] UIView Subview for Animation
问题描述
我的目标是我的动画UI,和我使用的UIView动画。问题是我需要一个以上的动画回事的时间,但显然我只能在同一时间执行一个UIView的动画。我也问过关于这个主题$ P $问题pviously(多的UIView动画),和所有的应答者说我必须设置一个委托到动画像的方法animationDidStop:performSelector:
,但如果我能,而不是子视图添加到主视图和每个同时执行的动画我想知道子视图。另外,我无法进行背靠背的动画,我想也许我可以执行的厂景的动画,然后对视图2没有下放。
例如:
//头
@属性(非原子,强)的UIView *厂景;
@属性(非原子,保留)的UIView *视图2;//实施
@synthesize厂景;
@synthesize视图2;// viewDidLoad中
厂景= [[UIView的页头] initWithFrame:方法CGRectMake(0,0,480,640);
视图2 = [[UIView的页头] initWithFrame:方法CGRectMake(0,0,480,640);view1.backgroundColor =的UIColor clearColor]
view2.backgroundColor =的UIColor clearColor][performAnimationsOn视图1]; //我不知道code我会把在这里,因为code
//我平时用的是[UIView的beginAnimation:@动画
//背景:无];但是这是一个类的方法,我不
//知道如何在一个特定的子视图执行的动画。
[performAnimationsOn视图2];
我没有看到这里的问题,如果你需要的是动画2 diffent意见同时做到以下几点:
//首先添加这些子视图
[self.view addSubview:视图1];
[self.view addSubview:视图2];
[UIView的beginAnimations:@动画1上下文:无];
[UIView的setAnimationDidStopSelector:@selector(animationDidStop:完成:上下文:)];
[UIView的setAnimationDelegate:个体经营];
[UIView的setAnimationDuration:1];
//使用视图1移动,改变α,变更改造等东西..
[UIView的commitAnimations];
另外添加的功能
- (无效)animationDidStop:(* NSString的)animationID完成:(NSNumber的*)完成环境:(无效*)上下文
{
如果([animationID isEqualToString:@动画1]){
[UIView的beginAnimations:@Animation2背景:无];
[UIView的setAnimationDidStopSelector:@selector(animationDidStop:完成:上下文:)];
[UIView的setAnimationDelegate:个体经营];
[UIView的setAnimationDuration:1];
//使用视图2移动,改变α,变更改造等东西..
[UIView的commitAnimations];
}
否则,如果([animationID isEqualToString:@Animation2]){
[UIView的beginAnimations:@动画3背景:无];
[UIView的setAnimationDidStopSelector:@selector(animationDidStop:完成:上下文:)];
[UIView的setAnimationDelegate:个体经营];
[UIView的setAnimationDuration:1];
//使用视图3移动,改变α,变更改造等东西..
[UIView的commitAnimations];
}
//等等.....
}
该动画应顺序发生
My goal is to animate my UI, and I am using UIView animations. The problem is I need more than one animation going on at a time, but apparently I can only perform one UIView animation at a time. I have asked questions on this topic previously (Multiple UIView Animations), and all the responders say I have to set a delegate to the animation with a method like animationDidStop:performSelector:
but I was wondering if I could instead add subviews to the main view and perform animations simultaneously on each subview. Also, I am unable to perform back to back animations, and I was thinking maybe I could perform an animation on view1 and then on view2 without delegating.
For example:
//Header
@property (nonatomic, strong) UIView *view1;
@property (nonatomic, retain) UIView *view2;
//Implementation
@synthesize view1;
@synthesize view2;
//ViewDidLoad
view1 = [[UIView alloc]initWithFrame:CGRectMake(0,0,480,640)];
view2 = [[UIView alloc]initWithFrame:CGRectMake(0,0,480,640)];
view1.backgroundColor = [UIColor clearColor];
view2.backgroundColor = [UIColor clearColor];
[performAnimationsOn View1]; //I don't know the code I would put here because the code
//I usually use is [UIView beginAnimation:@"animation"
//context:nil]; but that is a class method and I am not
//sure how to perform an animation on a specific subview.
[performAnimationsOn View2];
I dont see the problem here, if what you need is to animate two diffent views at once do the following:
//First add these subviews
[self.view addSubview:view1];
[self.view addSubview:view2];
[UIView beginAnimations:@"Animation1" context:nil];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:1];
//Do something with view 1 move, change alpha, change transformation etc..
[UIView commitAnimations];
Also add the following function
- (void) animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
if ([animationID isEqualToString:@"Animation1"]) {
[UIView beginAnimations:@"Animation2" context:nil];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:1];
//Do something with view 2 move, change alpha, change transformation etc..
[UIView commitAnimations];
}
else if ([animationID isEqualToString:@"Animation2"]) {
[UIView beginAnimations:@"Animation3" context:nil];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:1];
//Do something with view 3 move, change alpha, change transformation etc..
[UIView commitAnimations];
}
//And so on.....
}
The animations should occur sequentially
这篇关于UIView的子视图的动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!