简体   繁体   English

移动多个UIImageView对象

[英]Move multiple UIImageView objects

I want to add multiple UIImageView objects at run time. 我想在运行时添加多个UIImageView对象。 I just read that it's possible through NSMutableArray . 我刚刚读到它可以通过NSMutableArray

But I also want to move all the UIImageViews . 但我也想移动所有UIImageViews Is it possible to track which UIImageView I touched? 是否可以跟踪我触摸了哪个UIImageView

Please help me. 请帮我。 Any type of help will be appreciated. 任何类型的帮助将不胜感激。

Thanks 谢谢

You may need to rephrase your question but I'll see if I can help you out. 您可能需要重新表达您的问题,但是我会帮您解决。 To find what view is being touched, you can define the touchesBegan method in your view controller. 要查找正在触摸的视图,可以在视图控制器中定义touchesBegan方法。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [[event allTouches] anyObject]; //gets the touch object
    [touch.view thisIsAMethod]; 
    //once you declare touch, you can access what view is being touched with touch.view

}

Also, if you want to move a lot of UIImageViews at once, you can make them all subviews of one UIView by calling 另外,如果您想一次移动很多UIImageViews ,则可以通过调用使它们成为一个UIView的所有subviews

[oneBigUIView addSubview:oneUIImageView];

for every UIImageView . 对于每个UIImageView Then you can change the position of the UIView to move them all at once, since the coordinates of each UIImageView are in relation to their superview . 然后,您可以更改UIView的位置以一次全部移动它们,因为每个UIImageView的坐标都与它们的superview

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM