2014-03-28 67 views
3

在iPad中,當您將手指放在屏幕頂部或底部邊緣之外,然後將其拖動到屏幕上時,會顯示一個菜單。你知道我該怎麼做這樣的事情?iOS檢測到屏幕左邊緣外的拖動

+0

你可以使用手勢 –

回答

6
  • 這是一個特殊的手勢識別器類,在iOS 7中介紹。這是​​。它的文檔是here。一探究竟。

  • 要在模擬器中進行測試,只需從邊緣附近(〜15點)開始拖動即可。

  • 此外,您將不得不爲每個邊緣創建一個gestureRecognizer。你不能OR邊緣,所以UIRectEdgeAll將無法​​正常工作。

有一個簡單的例子here。希望這可以幫助!

1

那麼你可以做這樣的事情,這個例子是您希望您平移手勢的工作,只有當用戶刷卡從屏幕

首先的右側20像素內加手勢的情況下到你的窗口

- (void)addGestures { 
if (!_panGesture) {  
_panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)]; 
[_panGesture setDelegate:self]; 
[self.view addGestureRecognizer:_panGesture]; 
} 
} 

將檢查你收到的觸摸是否是一個平移手勢,然後執行你的行動因此

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {  
CGPoint point = [touch locationInView:self.view]; 
if (gestureRecognizer == _panGesture) {  
return [self slideMenuForGestureRecognizer:gestureRecognizer withTouchPoint:point]; 
} 
return YES; 
} 

後這裏是你如何檢查你的觸摸是否包含在你想要的區域

-(BOOL)isPointContainedWithinBezelRect:(CGPoint)point { 
    CGRect leftBezelRect; 
    CGRect tempRect; 
//this will be the width between CGRectMaxXEdge and the screen offset, thus identifying teh region 
    CGFloat bezelWidth =20.0; 
    CGRectDivide(self.view.bounds, &leftBezelRect, &tempRect, bezelWidth, CGRectMaxXEdge); 
    return CGRectContainsPoint(leftBezelRect, point); 
    }