你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> touchesBegan: withEvent: 不執行解決

touchesBegan: withEvent: 不執行解決

編輯:IOS開發綜合

touchesBegan: withEvent: / touchesMoved: withEvent: / touchesEnded: withEvent: 等只能被UIView捕獲(如有問題請指出對請指出,路過的大牛請勿噴),當我們創建

UIScrollView 或 UIImageView 時,當點擊時UIScrollView 或 UIImageView 會截獲touch事件,導致touchesBegan: withEvent:/touchesMoved: withEvent:/touchesEnded: withEvent: 等方法不執行。解決辦法:當UIScrollView 或 UIImageView 截獲touch事件後,讓其傳遞下去即可(就是傳遞給其父視圖UIView)

可以通過寫UIScrollView 或 UIImageView 的category 重寫touchesBegan: withEvent: / touchesMoved: withEvent: / touchesEnded: withEvent: 等來實現

// 
// UIScrollView+UITouch.m 
//  
// 
// Created by MLS on 15/11/20. 
// Copyright © 2015年 mls. All rights reserved. 
// 
 
#import "UIScrollView+UITouch.h" 
 
@implementation UIScrollView (UITouch) 
 
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event 
{ 
  // 選其一即可 
  [super touchesBegan:touches withEvent:event]; 
//  [[self nextResponder] touchesBegan:touches withEvent:event]; 
} 
 
@end 




  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved