我目前拥有UIImageView.clipsToBounds = NO;
并且效果很好,但我需要启用userInteraction
,这样如果触摸了子视图,我就可以回复触摸。任何人都知道如何保留UIImageView.clipsToBounds = NO;
但仍然允许用户在界限之外进行交互?
答案 0 :(得分:1)
你必须实现UIGestureRecognizerDelegate的方法。
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if (touch.view != YourImageView) { // accept only touchs on superview, not accept touchs on subviews
return NO;
}
return YES;
}
答案 1 :(得分:0)
启用UIImageView
用户互动默认UIImageView
userInteration将被禁用。
yourImageView.userInteractionEnabled = YES;
答案 2 :(得分:0)
处理点击UIImageView
的剪切边界的操作。在UIImageView的superview类上实现tochesBegan:withEvent:
。检查触摸位置是否在imageView边界的范围内,然后点击该位置。为实现此目的,请执行以下操作:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint point = [[touches anyObject] locationInView:self.imageView];
if(CGRectContainsPoint(self.imageView.bounds, point)) {
// Your code on tap of UIImgeView.
NSLog(@"image view is tapped");
}
}
这可能会对你有帮助。