簡體   English   中英

iOS:在子視圖中滑動手勢

[英]iOS: swipe gesture inside a subview

我應該在子視圖中實現滑動手勢; 此子視圖是斜視圖

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

我想在此視圖內實現滑動手勢,如果發生這種情況,我應該有一個NSLog指出該視圖內發生了滑動,這可能嗎?

與其他任何UIView一樣,可以添加一個手勢識別器:

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

問題出在UISwipeGestureRecognizer的屬性“ direction”。 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];

缺點是view2內但view1外部有某些區域會響應手勢識別器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM