2024年Web前端最全Core Animation实战三(图层几何学),web前端开发面试问题有哪些

总结

大厂面试问深度,小厂面试问广度,如果有同学想进大厂深造一定要有一个方向精通的惊艳到面试官,还要平时遇到问题后思考一下问题的本质,找方法解决是一个方面,看到问题本质是另一个方面。还有大家一定要有目标,我在很久之前就想着以后一定要去大厂,然后默默努力,每天看一些大佬们的文章,总是觉得只有再学深入一点才有机会,所以才有恒心一直学下去。

开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

最后效果如下:

Demo代码:

//

// ClockViewController.m

// LayerStudyDemo

//

// Created by apple on 2017/9/25.

// Copyright © 2017年 ZY. All rights reserved.

//

#import “ClockViewController.h”

@interface ClockViewController ()

@property (weak, nonatomic) IBOutlet UILabel *hourLabel;

@property (weak, nonatomic) IBOutlet UILabel *minuteLabel;

@property (weak, nonatomic) IBOutlet UILabel *secondLabel;

@property (nonatomic, weak) NSTimer *timer;

@end

@implementation ClockViewController

  • (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view from its nib.

self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(showTime) userInfo:nil repeats:YES];

}

-(void)showTime{

NSCalendar * calendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSCalendarIdentifierChinese];

NSUInteger units = NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;

NSDateComponents *components = [calendar components:units fromDate:[NSDate date]];

CGFloat hoursAngle = (components.hour / 12.0) * M_PI * 2.0;

//calculate hour hand angle //calculate minute hand angle

CGFloat minsAngle = (components.minute / 60.0) * M_PI * 2.0;

//calculate second hand angle

CGFloat secsAngle = (components.second / 60.0) * M_PI * 2.0;

//设置锚点

self.hourLabel.layer.anchorPoint =self.minuteLabel.layer.anchorPoint =self.secondLabel.layer.anchorPoint = CGPointMake(0.5f, 0.9f);

//rotate hands

self.hourLabel.transform = CGAffineTransformMakeRotation(hoursAngle);

self.minuteLabel.transform = CGAffineTransformMakeRotation(minsAngle);

self.secondLabel.transform = CGAffineTransformMakeRotation(secsAngle);

}

  • (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

/*

#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation

  • (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

// Get the new view controller using [segue destinationViewController].

// Pass the selected object to the new view controller.

}

*/

@end

  • 坐标系和Hit Testing

CALayer 并不关心任何响应链事件,所以不能直接处理触摸事件或者手势。但是它有一系列的方法帮你处理事件: -containsPoint:-hitTest:

-containsPoint:接受一个在本图层坐标系下的CGPoint,如果这个点在图层frame范围内就返回YES

-hitTest:方法同样接受一个CGPoint类型参数,而不是BOOL类型,它返回图层本身,或者包含这个坐标点的叶子节点图层。这意味着不再需要像使用-containsPoint:那样,人工地在每个子图层变换或者测试点击的坐标。如果这个点在最外面图层的范围之外,则返回nil。

//

// HitTestingViewController.m

// LayerStudyDemo

//

// Created by apple on 2017/9/25.

// Copyright © 2017年 ZY. All rights reserved.

//

#import “HitTestingViewController.h”

@interface HitTestingViewController ()

@property (weak, nonatomic) IBOutlet UIView *wildView;

@property (nonatomic, strong) CALayer *innerLayer;

@end

@implementation HitTestingViewController

  • (void)viewDidLoad {

[super viewDidLoad];

[self creatInnerLayer];

}

-(void)creatInnerLayer{

self.innerLayer = [CALayer layer];

self.innerLayer.frame = CGRectMake((self.wildView.frame.size.width-100)/2, (self.wildView.frame.size.height-100)/2, 100.0f, 100.0f);

self.innerLayer.backgroundColor = [UIColor blueColor].CGColor;

//add it to our view

[self.wildView.layer addSublayer:self.innerLayer];

}

// containsPoint 判断较麻烦,需要把坐标转换图层成每个坐标系下的坐标

最后

开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

大厂面试问深度,小厂面试问广度,如果有同学想进大厂深造一定要有一个方向精通的惊艳到面试官,还要平时遇到问题后思考一下问题的本质,找方法解决是一个方面,看到问题本质是另一个方面。还有大家一定要有目标,我在很久之前就想着以后一定要去大厂,然后默默努力,每天看一些大佬们的文章,总是觉得只有再学深入一点才有机会,所以才有恒心一直学下去。

  • 9
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值