【发布时间】:2015-01-29 20:03:15
【问题描述】:
我尝试移动 2 个 UIImageView。
当我拖动时,应该只移动一张图片。
我试图完成的是当我触摸并拖动 UIImageView 时移动 UIImageView。
这是我的 viewDidLoad :
-(void)viewDidLoad
{
[super viewDidLoad];
myImageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 200, 100)];
[myImageView setImage:[UIImage imageNamed:@"image1.png"]];
[self.view addSubview:myImageView];
myImageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(100, 200, 200,100)];
[myImageView1 setImage:[UIImage imageNamed:@"image2"]];
[self.view addSubview:myImageView1];
}
这是我的 touchesMoved 方法:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
// get touch event
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self.view];
for (UIImageView *image in [self.view subviews])
{
if ([touch view] == image)
{
// move the image view
image.center = touchLocation;
}
}
}
在这一行我没有得到图像视图
for (UIImageView *image in [self.view subviews])
可以获取当前触摸的 UIIamgeView 吗?
【问题讨论】:
-
这还不是问题。您需要告诉我们更多信息,例如: 1. 您想要完成什么。 2. 目前的结果是什么?我猜您正在尝试仅移动包含触摸的
UIImageView,但您需要更具体并提供更多详细信息。 -
感谢我编辑帖子,并添加更多信息。
-
你还没有真正告诉我们出了什么问题。
-
怎么了??你的意思是你拖两张图片而不是一张?
-
我现在不能移动图像,我尝试移动一个图像每次用户平移屏幕。