xcode 如何在目标 c 中移动图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8893244/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:01:18  来源:igfitidea点击:

how to move an image in objective c

objective-ciosxcodeuiimageviewuiimage

提问by Hacer sengul Akac

I want to move image to another x,y position. I try this code but not work it crash after 3 seconds. The error is: 2012-01-17 12:40:47.213 YapiKrediDemo[1986:207] -[Sozlesme moveImage:]: unrecognized selector sent to instance 0x6c316c0.

我想将图像移动到另一个 x,y 位置。我尝试使用此代码,但无法在 3 秒后崩溃。错误是:2012-01-17 12:40:47.213 YapiKrediDemo[1986:207] -[Sozlesme moveImage:]: 发送到实例 0x6c316c0 的无法识别的选择器。

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.

image1=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"GirisButton.png"]];

[NSTimer scheduledTimerWithTimeInterval: 3
                                 target: self
                               selector:@selector(moveImage:)
                               userInfo: nil repeats:YES];
}

-(void) moveImage
{
//[image1 setCenter: CGPointMake(634, 126)];
CGPoint pointOne=CGPointMake(634, 126);
image1.center=pointOne;
}  

How can I solve ?

我该如何解决?

回答by Shai Mishali

Your selector needs to be @selector(moveImage)without the colon. moveImage:would mean a parameter is expected, while your method delceration below doesn't accept any parameters.

您的选择器需要@selector(moveImage)没有冒号。 moveImage:将意味着需要一个参数,而下面的方法 delceration 不接受任何参数。

You could also just change the frame.

你也可以只改变框架。

 CGRect myFrame = image1.frame;
 myFrame.origin.x = 634;
 myFrame.origin.y = 126;
 image1.frame = myFrame;

回答by V1ru8

The selector is @selector(moveImage). No :at the end. Or you have to add a parameter to the moveImage method. That's what you should do. - (void)moveImage:(NSTimer*)timer

选择器是@selector(moveImage)。最后没有:。或者您必须向 moveImage 方法添加一个参数。这就是你应该做的。- (void)moveImage:(NSTimer*)timer