我正在为我的superview添加一个子视图。它应该在屏幕上显示动画。
代码:
HomeListingView=[[UIView alloc]initWithFrame:CGRectMake(10,10,300 , 300+190)];
[HomeListingView setBackgroundColor:[UIColor whiteColor]];
[UIView animateWithDuration:0.1 delay:0.5 options:UIViewAnimationOptionCurveEaseInOut animations:^{
[scrollSell addSubview:HomeListingView]; //scrollsell is the object of UIScrollView
}completion:^(BOOL finished){
NSLog(@"Done");
}];
我在这里做错了什么。或者还有另一种动画制作方法吗?
答案 0 :(得分:1)
假设您要将HomeListingView
移到屏幕上,请将代码更改为:
HomeListingView=[[UIView alloc]initWithFrame:CGRectMake(-300, -300 + 190, 300 , 300+190)]; // Create view with frame initially off screen
[HomeListingView setBackgroundColor:[UIColor whiteColor]];
[scrollSell addSubview:HomeListingView]; //scrollsell is the object of UIScrollView
[UIView animateWithDuration:0.1 delay:0.5 options:UIViewAnimationOptionCurveEaseInOut animations:^{
HomeListingView.frame = CGRectMake(10,10,300 , 300+190)]; // Change the frame to move it on screen
}completion:^(BOOL finished){
NSLog(@"Done");
}];
答案 1 :(得分:0)
这是方法:
HomeListingView =[[UIView alloc]init];
[HomeListingView setBackgroundColor:[UIColor redColor]];
[self.sclCeel addSubview:HomeListingView]; //scrollsell is the object of UIScrollView
[UIView animateWithDuration:0.1 delay:0.5 options:UIViewAnimationOptionCurveEaseInOut animations:^{
HomeListingView.frame = CGRectMake(10,10,300 , 300+190); // Set your view frame here.
}completion:^(BOOL finished){
NSLog(@"Done");
}];
答案 2 :(得分:0)
在动画块我们需要根据动画效果改变帧,你做错了,请看它
UIView * view = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
[self.view addSubview:view];
[view setBackgroundColor:[UIColor redColor]];
[UIView animateWithDuration:1.0
animations:^{
view.frame = CGRectMake(view.frame.origin.x-25, view.frame.origin.y-25, view.frame.size.width+50, view.frame.size.height+50);
} completion:^(BOOL finished) {
}];