【发布时间】:2014-06-25 02:45:08
【问题描述】:
在我的应用设置中,我有一个带有 4 个 ImageView 的导航控制器。其中 1 个可以拖动,而其他 3 个固定在视图的顶部。使用下面的代码,我进行了设置,以便用户将一个图像视图拖到他想去的图像视图中。所以要进入视图 1,他将可移动的图像视图拖到图像视图 1,依此类推。问题在于,随着图像视图的宽度,选择器视图可能同时触摸两个,这会产生嵌套视图控制器问题。有没有一种方法可以防止这种情况发生,除了将图像视图移动得太远以至于一次不可能选择多个视图?
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
// If the touch was in the placardView, move the placardView to its location
if ([touch view] == clock) {
CGPoint location = [touch locationInView:self.tabBarController.view];
clock.center = location;
BOOL isIntersecting = CGRectIntersectsRect(clock.frame, prayer.frame);
BOOL isIntersecting2 = CGRectIntersectsRect(clock.frame, fasting.frame);
BOOL isIntersecting3 = CGRectIntersectsRect(clock.frame, study.frame);
if(isIntersecting){
[self schedulePrayer];
NSLog(@"prayer");
}
if(isIntersecting2){
[self scheduleFasting];
NSLog(@"fasting");
}
if(isIntersecting3){
[self scheduleStudying];
NSLog(@"Studying");
}
return;
}
}
【问题讨论】:
-
你为什么不直接使用if ... else if ... else if?然后一次只会触发一个。
-
如果您将此作为答案发布,@Ricky 我会接受。
-
按要求发布。谢谢。 ;)
标签: ios objective-c uiimageview frame touches