how to create a moving image

試著忘記壹切 提交于 2019-12-25 06:47:05

问题


How do I create an image which moves into the screen? So it comes up from the bottom and stops when totally visible. I would also play with the speed and direction. It's not like scrolling of photos as demonstrated in the PhotosSroller example of Apple


回答1:


CGRect endFrame = [[self view] frame];
[imageView setFrame: CGRectMake([[self view] frame].origin.x, [[self view] frame].origin.y + 480.0, [[self view] frame].size.width, [[self view] frame].size.height)];
[UIView beginAnimations: nil context: NULL];
[UIView setAnimationDuration: 0.25];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[imageView setFrame: endFrame];
[UIView commitAnimations];

It's not tested but that will give you an idea.

Update:

For the sake of animation block

[imageView setFrame: CGRectMake([[self view] frame].origin.x, [[self view] frame].origin.y + 480.0, [[self view] frame].size.width, [[self view] frame].size.height)];

[UIView animateWithDuration: 1.0f animations: ^{
[imageView setCenter: [[self view] center]];
} ];

You can hide the imageView by reversing it.

(y)0 - imageView height = top
(x)0 - imageView width = left
[self view] height = bottom
[self view] width = right

Again not tested but will give you an idea how to use it.




回答2:


Look at UIView's animateWithDuration: methods. You basically change the frame and that method will animate the moving of the view. It's really simple, just read the documentation. If you need any help don't hesitate to ask.




回答3:


If I understand what you're trying to achieve, you should be able to get the result you're looking for with UIView animations by animating properties such as the location, and alpha of your image view. For example, if you had a view which started out fully transparent that you wanted to move to the center of your view controllers view, you might do something like this:

[UIView animateWithDuration: 0.25 animations: ^{  
    imageView.center = self.view.center;  
    imageView.alpha = 1.0f;  
}


来源:https://stackoverflow.com/questions/6145337/how-to-create-a-moving-image

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!