我想有我每打一次按钮移动图像。 它应该每次移动的像素的设定值。
我希望此搜索现在将有一个位置属性,但据我可以看到它doesnt't。
UIImageView *image1=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"indicator"]];
[self.view addSubview:image1];
...
谢谢
编辑: UIImageView *image1=[[UIImageView alloc]...
作为其它两个答案状态下,可以设置使用帧(或的CGRect)一个UIImageView的初始位置。 注意,对于CGRectMake的参数; x位置,y位置,x维度,y维度。
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 100, 100)];
[imgView setImage:[UIImage imageNamed:"image.png"]];
在每次按下一个按钮时移动图像,需要每个按钮被按下的时间来更新框架。 然而,x和框架的y坐标是只读的,所以你需要创建一个新的框架,像这样:
CGRect oldFrame = imgView.frame;
CGRect newFrame = CGRectMake(oldFrame.origin.x + 10, oldFrame.origin.y, oldFrame.size.width, oldFrame.size.height);
imgView.frame = newFrame;
请注意,此代码移动图像10个指向右侧(沿x轴)。
你需要一个ImageView的显示一个UIImage的。
UIImage *image1=[UIImage imageNamed:@"indicator.png"];
UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(10,10,100,100)];
iv.image = image1;
[self.view addSubView:iv];
[image1 release];
[iv release];
您可以设置的UIImageView的框架:
UIImageView* imgv= [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 120, 120)];
imgv.image = [UIImage imageNamed:@"image.png"];
在这里,你将不得不通过试验和错误设置框的位置。