[英]Sending touch gestures to UIImageView subview of UIScrollView
我編寫了一個UIImageView,可以在其中繪制內容。 因此,它跟蹤並記錄用戶的觸摸。 在窗口中使用時,效果很好。
但是,然后我將其添加為駐留在視圖控制器中的UIScrollView的子視圖。 當我現在嘗試使用它時,UIImageView內部的觸摸手勢只是滾動整個視圖,而不是在UIImageView內部繪制。
如何將同樣位於UIImageView內部的對UIScrollView所做的手勢引用到UIImageView。
我希望這是有道理的
最好的祝福
編輯:我已經將所有以下屬性: canCancelContentTouches
, exclusiveTouch
和delaysContentTouches
為NO。
現在,當我觸摸UIImageView時,它不會滾動,但仍不會調用以下方法: touchesBegan:withEvent:
, touchesMoved:withEvent:
或touchesEnded:withEvent:
分別位於ViewController中
設置exclusiveTouch
的的UIImageView的財產YES
(這意味着,當的UIImageView被觸摸時,那一抹不會對任何其他視圖效果)
您希望應用程序如何決定是觸摸滾動視圖還是在圖像視圖中繪制?
假設您要一根手指來畫,而兩根手指要滾動。 如果您的目標是iOS 5.0,則很簡單:
self.scrollView.panGestureRecognizer.minimumNumberOfTouches = 2;
如果您要定位的是較早的iOS,則不能使用panGestureRecognizer
屬性。 您必須在滾動視圖的gestureRecognizers
屬性中進行挖掘以找到正確的識別器。 在此處查看我的答案以獲取示例代碼。
UIScrollView不會為此觸發觸摸事件方法,因此必須子類化UIScrollView。 像下面。
@interface AppScrollView : UIScrollView {
}
- (id)initWithFrame:(CGRect)frame;
@結束
#import "AppScrollView.h"
@implementation AppScrollView
- (id)initWithFrame:(CGRect)frame
{
if ([super initWithFrame:frame]){
}
return self;
}
- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event
{
// If not dragging, send event to next responder
if (!self.dragging)
[self.nextResponder touchesEnded: touches withEvent:event];
else
[super touchesEnded: touches withEvent: event];
}
@end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.