Iphone 通过选择器更改uiimageview位置

Iphone 通过选择器更改uiimageview位置,iphone,Iphone,我试图在延时后更改图像视图的位置,如下面的代码所示 CGPoint pointOne=CGPointMake(150, 200); UIImageView *sampleImage=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hello.png"]]; [sampleImage performSelector:@selector(setCenter:) withObject:[NSValue valueWithCG

我试图在延时后更改图像视图的位置,如下面的代码所示

    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];

它无法正常工作,因为image view不接受nsvalue plz,也不接受将cgpoint或cgrect作为对象传递的任何其他解决方案。提前感谢。

只需创建另一个方法,即使在给定NSValue的ViewController中,也可以将其转换回CGPoint并设置为UIIMageView。 稍后使用
performSelector:withObject:afterDelay:
调用此方法。
如果您甚至需要传递对UIImageView的引用,您可以传递一个包含视图和值的NSDictionary。

只需创建另一个方法,即使在给定NSValue的ViewController中,也可以将其转换回CGPoint并设置为UIImageView。 稍后使用
performSelector:withObject:afterDelay:
调用此方法。
如果您甚至需要传递对UIImageView的引用,您可以传递一个包含视图和值的NSDictionary。

另一个选项是使用核心动画:

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

如果不希望视图移动到位,也可以将动画持续时间设置为零,或将其透明度设置为淡入。另一个选项是使用核心动画:

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

如果不希望视图移动到位,则还可以将动画持续时间设置为零,或将其透明度设置为淡入。

您不能使用
setCenter:
CGPoint
以外的任何内容作为参数传递,您不能使用
setCenter:
CGPoint
以外的任何内容作为参数传递