[英]animate image/UIView iOS
On the homepage of my application I want to animate a PNG image sliding into the view, then sliding out again before a second image slides in, then out. 在我的应用程序的主页上,我想为一个PNG图像制作动画,使其滑入视图,然后再次滑出,然后再滑入另一个图像,然后滑出。 Time just for the viewer to read before each disappears. 观看者在消失之前要阅读的时间。 I dont know how to do this and would like some input ? 我不知道该怎么做,想要一些输入吗? seems pretty simple I hope it is and someone can direct me how to do it. 似乎很简单,我希望是这样,有人可以指导我该怎么做。 I also want it on loop, so whenever you go back to the screen it will animate still. 我也希望它能循环播放,因此无论何时回到屏幕,它都将保持动画。
Any ideas please? 有什么想法吗? Only a day or so to finish 仅需一天左右即可完成
You can use Core Animation for this. 您可以为此使用Core Animation。 It's real easy to do. 这真的很容易做到。 Example animation: 动画示例:
UIImageView *imageView = ...;
imageView.frame = CGRectMake(-160, 100, 250, 200);
[UIView animateWithDuration:1.5 animations:^{
imageView.frame = CGRectMake(160, 100, 250, 200);
}];
This animates a UIImageView
from x-coordinate -160 to 160 in 1.5 seconds. 这样可以在1.5秒内将UIImageView
的x坐标-160设置为160。
More or less just expanding on Tom van Zummeren's answer. 或多或少只是扩大了汤姆·范·祖默伦的答案。 This should be enough to get the basic idea across. 这应该足以使基本思想得以传播。
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
UIImageView *myImageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, -280, 280, 280)];
[myImageView setImage:[UIImage imageNamed:@"1.png"]];
[self.view addSubview:myImageView];
[UIView animateWithDuration:2.0 delay:1.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
[myImageView setCenter:self.view.center];
}completion:^(BOOL done){
[UIView animateWithDuration:2.0 delay:3.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
[myImageView setCenter:CGPointMake(myImageView.center.x, self.view.bounds.size.height + (myImageView.bounds.size.height / 2))];
}completion:^(BOOL done){
[myImageView setFrame:CGRectMake(20, -280, 280, 280)];
NSLog(@"%@",NSStringFromCGRect(myImageView.frame));
[myImageView setImage:[UIImage imageNamed:@"2.png"]];
}];
}];
}
//Starting point //初始点
pImgFlowing.frame = CGRectMake(544, 817, 84, 18);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
//Ending point //终点
pImgFlowing.frame = CGRectMake(544, 774, 84, 61);
[UIView commitAnimations];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.