對不起,如果我忽略了一個潛在的回答我的問題,但我在使用的UITapGestureRecognizer與子視圖UIViewController類裏面一個UILabel麻煩......的iOS使用UITapGestureRecognizer用的UILabel刷卡到下一個頁面
基本上,我創建了一個具有UILabel和一些其他不相關元素的自定義UIViewController。 但是,此自定義UIViewController位於啓用了分頁的自定義UIScrollView中,並且標籤已被偏移到足以讓您看到下一個UIViewController的標籤。我想要做的是,當用戶觸摸「下一個」標籤時,scrollRectToVisible:animated:方法觸發,實質上在不滾動的情況下切換頁面。 CustomViewController的UILabel位於頂部。
下面是添加UITapGestureRecognizer到CustomViewController的的UILabel當容器UIScrollView的一個示例代碼:
[scrollView addSubview:CustomViewController];
- (void) addSubview: (CustomViewController *) view {
// create view's frame here...
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(fireScrollRectToVisible:view)]; // this is the current problem like a lot of people out there...
[view.Label addGestureRecognizer:tap];
// [super addSubview:view.view];
}
- (void) fireScrollRectToVisible: (CustomViewController *) cvc {
CGRect frame = CGRectMake(cvc.view.frame.origin.x, cvc.view.frame.origin.y, 320, 480);
[scrollView scrollRectToVisible: frame animated:YES];
}
我最初以爲這將是容易的,但是由於@selector不允許你把論點它這令人難以置信。我想我需要的是訪問CustomViewController的框架並設置scrollRectToVisible,但我不知道了...
我試過這個帖子,但我很新的Objective-C和我不完全瞭解hitTest:withEvent: 我假設hitTest:(CGPoint)與視圖的邊界有關係嗎?
UITapGestureRecognizer initWithTarget:action: method to take arguments?
如果任何人都可以點我這將是偉大正確的方向。 任何幫助將不勝感激!
令人驚歎!這是一個非常簡單的解決方案,我完全忘記了superview的屬性。非常感謝! – Bill
打敗我吧!很好的答案。 – kevboh
@不用客氣。 :) – looyao