开发者

how to create a moving image

How do I create an image which moves into the screen? So it comes up from the bottom and sto开发者_StackOverflow社区ps 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


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.


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.


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;  
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜