AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// 初始化 window
self.window = [[UIWindow alloc] initWithFrame : [[UIScreen mainScreen] bounds]];
// 铺满全屏
CGRect frame = self.window.bounds;
// 初始化 view
BNRHypnosisView *view = [[BNRHypnosisView alloc] initWithFrame:frame];
// 给当前 window 添加 子view
[self.window addSubview:view];
// 设置屏幕背景
// 设置该 window 为主window, 设置为可见
[self.window makeKeyAndVisible];
return YES;
}
BNRHypnosisView.m
#import "BNRHypnosisView.h"
@implementation BNRHypnosisView
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
CGRect bounds = self.bounds;
// 计算圆心
CGPoint center;
center.x = bounds.origin.x + bounds.size.width / 2.0;
center.y = bounds.origin.y + bounds.size.height / 2.0 ;
// 使最外层圆形称为视图的外接圆
float maxRadius = hypot(bounds.size.width, bounds.size.height) / 2.0;
// 初始化路径绘制工具
UIBezierPath *path = [[UIBezierPath alloc] init];
path.lineWidth = 10;
[[UIColor lightGrayColor] setStroke];
// 根据 圆心 半径 起至弧度 绘制路径
for (float currentRadius = maxRadius; currentRadius > 0; currentRadius -= 20) {
[path moveToPoint:CGPointMake(center.x + currentRadius, center.y)];
[path addArcWithCenter:center radius:currentRadius startAngle:0.0 endAngle: M_PI * 4.0 clockwise: YES];
}
// 绘制
[path stroke];
}
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor whiteColor];
}
return self;
}
@end
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。