tags:

views:

34

answers:

2

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.

+1  A: 

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.

rano
thx for ur reply. but i want another way without creating new method...
KingofHeaven
you cannot use `setCenter:` by passing anything but a `CGPoint` as argument
rano
A: 

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.

St3fan