ZZCameraFocusView.m
1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// ZZCameraFocusView.m
// ZZFramework
//
// Created by Yuan on 15/12/21.
// Copyright © 2015年 zzl. All rights reserved.
//
#import "ZZCameraFocusView.h"
@interface ZZCameraFocusView()
@property (strong, nonatomic) UIImageView *focus;
@property (strong, nonatomic) NSTimer *timer;
@end
@implementation ZZCameraFocusView
-(instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor clearColor];
_focus = [[UIImageView alloc]init];
_focus.image = [UIImage imageNamed:@"camera_focus_pic.png"];
}
return self;
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:touch.view];
_focus.frame = CGRectMake(0, 0, 80, 80);
_focus.center = point;
[self addSubview:_focus];
[self shakeToShow:_focus];
_timer = [NSTimer scheduledTimerWithTimeInterval:3.0f target:self selector:@selector(hideFocusView) userInfo:nil repeats:YES];
if ([self.delegate respondsToSelector:@selector(cameraFocusOptions:)]) {
[self.delegate cameraFocusOptions:self];
}
}
- (void) shakeToShow:(UIView*)aView{
CAKeyframeAnimation* animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
animation.duration = 0.5;
NSMutableArray *values = [NSMutableArray array];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.2, 1.2, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9, 0.9, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
animation.values = values;
[aView.layer addAnimation:animation forKey:nil];
}
-(void) hideFocusView
{
[_focus removeFromSuperview];
[_timer invalidate];
}
@end