开发者

changing uiimageview position through selector

i'm trying to change the position of my image view after time delay like 开发者_如何学编程in the following code

    CGPoint pointOne=CGPointMake(150, 200);
 UIImageView *sampleImage=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hello.png"]];
 [sampleImage performSelector:@selector(setCenter:) withObject:[NSValue valueWithCGPoint:pointOne] afterDelay:0.5];

it does not works properly because image view does not accept the nsvalue plz say any other solution to pass the cgpoint or cgrect as the object. Thanks in advance.


Just create another method, even in your ViewController that given an NSValue, transforms it back to CGPoint and set it to the UIIMageView. Later call this method with performSelector:withObject:afterDelay:. If you need to pass even the reference to the UIImageView you can pass a NSDictionary containing both the view and the value.


Another option is to use core animation:

[UIView beginAnimations: @"MyMoveAnimation" context: nil];
[UIView setAnimationDelay: 0.5];
UIImageView* view = ... get view ...;
view.center = ... new center ...;
[UIView commitAnimations];

If you don't want the view to move into place then you can also set the animation duration to zero, or set it's transparancy so that it fades in.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜