我的主视图中有很多UIImageViews
,其中一些包含图片,其他为空白。我有安装代码,它将检查当前哪个UIImageView
包含图像。同时,此代码将确保允许将带有图像的UIImageView
移动。
现在发生的事情是:在移动选定的UIImageView
时(由于某种原因并且是相当随机的),图像将不会停留在屏幕上其他UImageViews
的顶部。我之所以说这是随机的,是因为它将停留在其他一些视图之上,而不是其他视图之上。
该行为是意外的,会出现一些问题:
UIImageView
应该滑到另一个。 UIImageViews
包含图像时才允许移动它们。因此,如果UIImageView
在另一个不包含图片的图片下面,则我无法触摸并再次移动它。好像卡在了适当的位置。 请注意,我根本没有为该代码设置子视图,因此发生这种现象的原因不在我的范围内。
所以我的问题可以归结为,有什么方法可以告诉代码:
UIImageView
,请允许我移动UIImageView
。 UIImageView
取代(位于其他所有UIImageViews
之上)。 代码参考:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{UITouch *touch;
UITouch *touch;
CGPoint touchLocation;
for (UIImageView *fruit in fruitArray)
{
// Check that the UIImageView contains an image
if([fruit image] != nil)
{
// Get the touch event.
touch = [touches anyObject];
// Get the location for the touched object within the view.
touchLocation = [touch locationInView:[self view]];
// Bring the UIImageView touch location to the image's center.
if([touch view] == fruit)
{
fruit.center = touchLocation;
}
}
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
//allow the selected event (in our case a UIImageView) to be dragged
[self touchesBegan:touches withEvent:event];
}
谢谢您的帮助!让我知道您是否需要更好的解释
最佳答案
[self.view bringSubviewToFront:imageView];
这就是您想要的...