2011-12-28 91 views
1

我應該在子視圖內實施輕掃手勢;此子視圖是斜視圖iOS:在子視圖內輕掃手勢

view1.transform = CGAffineTransformMakeRotation((54 * -M_PI)/180); 

我想實現這個視圖內的滑動手勢,如果它發生了,我應該有一個NSLog的是說,刷卡此視圖內發生,這可能嗎?

回答

5

正如任何其他的UIView,它可以添加一個手勢識別:

UISwipeGestureRecognizer *swipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipe:)]; 
[view1 addGestureRecognizer:swipeGestureRecognizer]; 

問題在於UISwipeGestureRecognizer的財產「方向」。 Apple關於此屬性的文檔:

此手勢識別器的滑動允許方向。

因爲視圖被旋轉時,旋轉方向沿着。如果視圖被旋轉180度和用戶刷右,手勢識別把它看作一個左滑動。我建議使用應該放置手勢識別器的包裝視圖。試試這個:

UIView *view2 = [[UIView alloc] initWithFrame:view1.frame]; 
[view1.superview addSubview:view2]; 

view2.backgroundColor = [UIColor clearColor]; 
UISwipeGestureRecognizer *swipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipe:)]; 
[view2 addGestureRecognizer:swipeGestureRecognizer]; 

缺點是有視圖2,但外界廠景內的某些區域,這將在手勢識別響應。

相關問題