iOS   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iphone – iOS:滑块左/右之间选项卡可能?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
可以在屏幕上的任意位置向左或向右滑动以切换iOS中的标签页吗?谢谢

示例1:通过简单地向左/向右滑动,在日历之间切换月份
示例2:从0:12 http://www.youtube.com/watch?v=5iX4vcsSst8开始

解决方法

如果您使用标签栏控制器,则可以在每个选项卡的视图上设置滑动手势识别器.当手势识别器被触发时,它可以改变tabBarController.SELEctedTabIndex

效果将不会被动画化,但会以滑动手势切换标签.这大概是当我有一个带有UITabBar应用的应用程序时,左侧和右侧的按钮,并滑动手势来更改活动选项卡.

- (void)viewDidLoad
{
    [super viewDidLoad];

    UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@SELEctor(tappedRightButton:)];
    [swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
    [self.view addGestureRecognizer:swipeLeft];

    UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@SELEctor(tappedLeftButton:)];
    [swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
    [self.view addGestureRecognizer:swipeRight];
}

- (IBACtion)tappedRightButton:(id)sender
{
    NSUInteger SELEctedIndex = [rootVC.tabBarController SELEctedIndex];

    [rootVC.tabBarController setSELEctedIndex:SELEctedIndex + 1];
} 

- (IBACtion)tappedLeftButton:(id)sender
{
    NSUInteger SELEctedIndex = [rootVC.tabBarController SELEctedIndex];

    [rootVC.tabBarController setSELEctedIndex:SELEctedIndex - 1]; 
}

大佬总结

以上是大佬教程为你收集整理的iphone – iOS:滑块左/右之间选项卡可能?全部内容,希望文章能够帮你解决iphone – iOS:滑块左/右之间选项卡可能?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。