当我将触摸事件传递给父视图时,MyScrollView不响应触摸。

3
我是一位有用的助手,可以翻译文本。
我有一个带有ScrollView子视图的ViewController,这些子视图中有一个子视图。以下是层次结构:
AppDelegate - MyViewController - ScrollView(来自xib)- MyScrollViewSubClass
// MyViewController: // .h
@interface MyViewController : UIViewController<MyScrollViewSubClassDelegate,UIScrollViewDelegate> {
    UIScrollView            *scrollView; // Loaded from xib 
}

@property(nonatomic,retain) IBOutlet UIScrollView *scrollView;

@end

// .m

@implementation MyViewController

@synthesize scrollView;

- (void)viewDidLoad {
    [super viewDidLoad];

    scrollView.delegate = self;

    MyScrollViewSubClass *myScrollView = [[MapScrollView alloc] init];
    myScrollView.delegate = self;
    myScrollView.myDelegate = self;

    scrollView addSubview:mapScrollView];
}

// The MyScrollViewSubClassDelegate @required method

- (void) onDoubleTapLocation: (CGPoint)tapPoint
{
    // Working,,,NSLog shown that this line is Working... 
}

我的ScrollView子类 + 代理 // .h
// Protocol
@protocol MyScrollViewSubClasswDelegate <NSObject>
@required
- (void) onDoubleTapLocation: (CGPoint)tapPoint;
@end

//Interface

@protocol MyScrollViewSubClass;

@interface MyScrollViewSubClass : UIScrollView <UIScrollViewDelegate> {
    id <MyScrollViewSubClasswDelegate> myDelegate;

    // Another vars..   
}

@property (nonatomic,assign) id<MyScrollViewSubClasswDelegate> myDelegate;

- (void)handleDoubleTap;

@end

// .m

@implementation MyScrollViewSubClass
@synthesize myDelegate;

- (id)initWithFrame:(CGRect)frame
{
    if ((self = [super initWithFrame:frame])) {

        // Another Code Here...

        self.delegate = self; // delegate for UIScrollView
        self.myDelegate = self;

        //Another Code Here...

    }
    return self;
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
   if(isDoubleTap)
   {
      //Call handle double tap
      [self handleDoubleTap];
   }
}

- (void)handleDoubleTap {
    [self.myDelegate onDoubleTapLocation: tapLocation];
}

发生的情况是在MyViewController上双击有效,但现在我无法从MyViewController滚动和捏合缩放MyScrollViewSubClass,欢迎任何批评、评论或更好的方法...
解决方案:
我两次在MyViewController上分配了代理
原来是:
myScrollView.delegate = self;
myScrollView.myDelegate = self;

应该是:

应为:

myScrollView.myDelegate = self;

问候,
Ferry Hattawidian

1
isDoubleTap是如何设置的?另外,请澄清一下你上一句话,我猜你是指“但是我无法滚动和缩放...”这样理解对吗? - jer
是的,那是我的笔误... 我通过计算触摸次数来检查触摸是否为双击或单击 --> 如果([touches count] == 2) { isDoubleTap = YES;} - DoogyHtw
1个回答

0

问题已解决:

我在MyViewController上两次分配了委托

现在已经解决:

myScrollView.delegate = self; 
myScrollView.myDelegate = self; 

应该是:

myScrollView.myDelegate = self; 

其他都运行良好...谢谢大家...


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接