屏蔽系统自带UIViewController左向右滑动实现返回的功能

要屏蔽某一个UIViewController的系统自带的右滑手势实现返回的功能。如下步骤:

①、在.m文件中实现如下代码:(一般写在viewDidLoad方法中)

    if ([[UIDevice currentDevice].systemVersion floatValue]>=7.0) {
        if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
            self.navigationController.interactivePopGestureRecognizer.enabled = YES;
            self.navigationController.interactivePopGestureRecognizer.delegate = self;
        }
    }

②、在此viewController的头文件中加入代理<UIGestureRecognizerDelegate>;

③、实现代理方法

#pragma mark、
#pragma mark UIGestureRecognizerDelegate

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
    if ([self.navigationController.viewControllers count] == 1) {
        return NO;
    }else{
        return YES;
    }
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 Objective-C 中,系统自带的选择弹窗是通过使用 UIAlertController实现的。以下是实现步骤: 1.导入头文件: ```objective-c #import <UIKit/UIKit.h> ``` 2.创建 UIAlertController 对象并设置标题、消息和样式: ```objective-c UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"选择性别" message:nil preferredStyle:UIAlertControllerStyleActionSheet]; ``` 3.创建 UIAlertAction 对象,并添加到 UIAlertController 中: ```objective-c UIAlertAction *maleAction = [UIAlertAction actionWithTitle:@"男" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { // 处理选择男性的逻辑 }]; UIAlertAction *femaleAction = [UIAlertAction actionWithTitle:@"女" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { // 处理选择女性的逻辑 }]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]; [alertController addAction:maleAction]; [alertController addAction:femaleAction]; [alertController addAction:cancelAction]; ``` 4.在需要弹出选择弹窗的地方,使用 presentViewController 方法显示 UIAlertController: ```objective-c UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController; [rootViewController presentViewController:alertController animated:YES completion:nil]; ``` 这样就可以实现一个简单的选择性别的系统自带弹窗了。你可以根据自己的需要调整样式和逻辑处理。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值