美文网首页
iOS 设置扫码框、控制器多层跳转

iOS 设置扫码框、控制器多层跳转

作者: 烟雨痕 | 来源:发表于2018-04-10 20:24 被阅读5次

知识小结一

绘制扫码区域

    CAShapeLayer *cropLayer = [[CAShapeLayer alloc] init];
    //绘制路径创建
    CGMutablePathRef path = CGPathCreateMutable();
    //扫码高亮区域
    CGPathAddRect(path, nil, CGRectMake((ScreenWidth - 280) / 2, (ScreenHeight - 280) / 2,  280, 280));
    CGPathAddRect(path, nil, self.view.bounds);
  
    //填充规则
    cropLayer.fillRule = kCAFillRuleEvenOdd;
    cropLayer.path = path;
    //填充背景色
    cropLayer.fillColor = [UIColor colorWithRed:0 / 255.0 green:0 / 255.0 blue:0 / 255.0 alpha:0.4].CGColor;
    [cropLayer setNeedsDisplay];
    [self.view.layer addSublayer:cropLayer];

实际效果如下:

WechatIMG16.jpeg

备注:四个角加的是四张小图片。

知识小结二

一、A push B push C present D, D需要返回到A。

解决方案之一(大家有的其他解决方案可以分享下):

D中代码:

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self dismissViewControllerAnimated:YES completion:^{
        [self.navigationController popViewControllerAnimated:NO];//等于先返回到D
        [[NSNotificationCenter defaultCenter] postNotificationName:@"popRoot" object:self userInfo:nil];

    }];
}

A中代码如下:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"大于";
    self.view.backgroundColor = [UIColor blueColor];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(popToSelf) name:@"popRoot" object:nil];
}

#pragma mark -- 通知响应事件
- (void)popToSelf {
    [self.navigationController popToViewController:self animated:YES];
}

备注:记得在A中移除通知,iOS9.0以后自动移除。

二、A push B push C push D push E, E返回到B 或者C时:

E中代码:

//前提是它们在同一个navigationController栈中
//取出B控制器
B *BVC = [self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count - 4];
 [self.navigationController popToViewController: BVC animated:YES];
//取出C控制器
C *CVC = [self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count - 3];
 [self.navigationController popToViewController: CVC animated:YES];

相关文章

网友评论

      本文标题:iOS 设置扫码框、控制器多层跳转

      本文链接:https://www.haomeiwen.com/subject/sfonhftx.html