iOS 利用mask layer 使view中扣掉一块露出下边的view
2015-11-26 16:58
751 查看
#define SCREEN_WIDTH [[UIScreen mainScreen] bounds].size.width
#define SCREEN_HEIGHT [[UIScreen mainScreen] bounds].size.height
- (void)addMask{
UIButton * _maskButton = [[UIButton alloc] init];
[_maskButton setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
[_maskButton setBackgroundColor:[UIColor colorWithWhite:0 alpha:0.7]]; [self.view addSubview:_maskButton];
//create path
UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
// MARK: circlePath
[path appendPath:[UIBezierPath bezierPathWithArcCenter:CGPointMake(SCREEN_WIDTH / 2, 200) radius:100 startAngle:0 endAngle:2*M_PI clockwise:NO]];
// MARK: roundRectanglePath
[path appendPath:[[UIBezierPath bezierPathWithRoundedRect:CGRectMake(20, 400, SCREEN_WIDTH - 22 * 20, 100) cornerRadius:15] bezierPathByReversingPath]];
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = path.CGPath;
[_maskButton.layer setMask:shapeLayer];
}
#define SCREEN_HEIGHT [[UIScreen mainScreen] bounds].size.height
- (void)addMask{
UIButton * _maskButton = [[UIButton alloc] init];
[_maskButton setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
[_maskButton setBackgroundColor:[UIColor colorWithWhite:0 alpha:0.7]]; [self.view addSubview:_maskButton];
//create path
UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
// MARK: circlePath
[path appendPath:[UIBezierPath bezierPathWithArcCenter:CGPointMake(SCREEN_WIDTH / 2, 200) radius:100 startAngle:0 endAngle:2*M_PI clockwise:NO]];
// MARK: roundRectanglePath
[path appendPath:[[UIBezierPath bezierPathWithRoundedRect:CGRectMake(20, 400, SCREEN_WIDTH - 22 * 20, 100) cornerRadius:15] bezierPathByReversingPath]];
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = path.CGPath;
[_maskButton.layer setMask:shapeLayer];
}
相关文章推荐
- iOS---block传值用法
- iOS 编写与圆有关的控件
- Xcode7制作framework教程 iOS9
- ios9邮箱添加163邮箱
- iOS AVPlayer pop 释放内存 崩溃
- iOSMVC设计模式
- 通过Safari浏览器获取iOS设备UDID(设备唯一标识符)
- iOS setter 与 getter方法
- iOS 让textField光标移动位置
- iOS如何让主界面不显示NavigationBar
- ios 常用字符串的操作
- IOS 常用第三方类整理
- iOS 学习日志:infoplist常用设置
- IOS触摸事件处理(如何处理多个触摸点)
- iOS进程间通信之CFMessagePort
- iOS屏幕旋转
- iOS音乐播放器实现后台播放锁屏界面控制
- iOS开发多线程-自定义NSOperation
- 真机调试问题:Unable to find a team with the given Team ID
- iOS开发笔记6:图片轮播及其无限循环效果,ios笔记