0
我有UITabBarController與2 ViewController添加它。所以,現在當我們點擊特定標籤時,所有標籤切換正常。我在TabBarController中添加了UISwipeGestureRecognizer,它可以將TabBar從左到右或從左向右劃過。UITabBarController與UISwipeGestureRecognizer
但我當我嘗試由右至左或從左向右輕掃,它不檢測我的手勢
這裏是我的TabBarController
#import "TabBarController.h"
@implementation TabBarController
-(void)viewDidLoad{
UISwipeGestureRecognizer *leftToRightGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftToRightSwipeDidFire)];
leftToRightGesture.direction = UISwipeGestureRecognizerDirectionRight;
[self.tabBarController.tabBar addGestureRecognizer:leftToRightGesture];
UISwipeGestureRecognizer *rightToLeftGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightToLeftSwipeDidFire)];
rightToLeftGesture.direction = UISwipeGestureRecognizerDirectionLeft;
[self.tabBarController.tabBar addGestureRecognizer:rightToLeftGesture];
}
- (void)leftToRightSwipeDidFire {
UITabBar *tabBar = self.tabBarController.tabBar;
NSInteger index = [tabBar.items indexOfObject:tabBar.selectedItem];
if (index > 0) {
self.tabBarController.selectedIndex = index - 1;
} else {
return;
}
}
- (void)rightToLeftSwipeDidFire {
UITabBar *tabBar = self.tabBarController.tabBar;
NSInteger index = [tabBar.items indexOfObject:tabBar.selectedItem];
if (index < tabBar.items.count - 1) {
self.tabBarController.selectedIndex = index + 1;
} else {
return;
}
}
@end
在選項卡之間滑動以進行滑動並不是一項非常常見的活動,不太直觀。我建議你重新考慮這樣做。當你刷卡時,你的「... SwipeDidFire」方法是否被調用? – fsb
解決,它沒有檢測到刷卡的原因是因爲它必須是IBAction @fbara –