因此,進出口讓與的PageControl一個頁面(這是與指示點你是哪個頁面多個視圖的頁面),我的代碼看起來像在viewDidLoad
如下:UISwipeGestureRecognizer只有一個方向努力
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeAction:)];
UIView *temp = [[UIView alloc]initWithFrame:self.view.frame];
temp.backgroundColor = [UIColor clearColor];
[temp addGestureRecognizer:swipe];
[self.view addSubview:temp];
而且在swipeAction選擇我:
- (void)swipeAction: (UISwipeGestureRecognizer *)sender{
NSLog(@"Swipe action called");
if (sender.direction == UISwipeGestureRecognizerDirectionLeft) {
//Do Something
}
else if (sender.direction == UISwipeGestureRecognizerDirectionRight){
//Do Something Else
}
}
令我驚訝的是,當你滑動到右側(即else if
塊被調用)此方法僅適用。當你向左滑動時,swipeAction
甚至不會被調用!這很奇怪,爲什麼會發生這種情況,我應該如何更改我的代碼?任何答覆表示讚賞。非常感謝!
該導航控制器內是否帶有此識別器的視圖? –
@SimonGoldeen不,它只是一個普通的'UIView' – ddolce