#define kScreenWidth [[UIScreen mainScreen] bounds].size.width
#define kScreenHeight [[UIScreen mainScreen] bounds].size.height
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
#import "ViewController.h"
#import "Masonry.h"
@interface ViewController ()<CAAnimationDelegate>{
}
@property (nonatomic , strong) UIView *backView;
@property (nonatomic , strong) UIImageView *imageV;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *taskBtn = [UIButton buttonWithType:UIButtonTypeCustom];
taskBtn.frame = CGRectMake(kScreenWidth-100, kScreenHeight-150, 65, 67);
[taskBtn setBackgroundImage:[UIImage imageNamed:@"task_button_image"] forState:UIControlStateNormal];
[taskBtn addTarget:self action:@selector(taskButtonClickEvent) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:taskBtn];
}
#pragma mark --- backView create
-(void)setUpBackView{
if (!_backView) {
_backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
_backView.backgroundColor = [UIColorFromRGB(0x000000) colorWithAlphaComponent:0.5];
[self.view addSubview:_backView];
_backView.userInteractionEnabled = YES;
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backViewClickEvent)];
[_backView addGestureRecognizer:singleTap];
_imageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
_imageV.image = [UIImage imageNamed:@"task_view_image"];
[_backView addSubview:_imageV];
// [_imageV mas_makeConstraints:^(MASConstraintMaker *make) {
// make.left.mas_equalTo(0);
// make.top.mas_equalTo(0);
// make.width.mas_equalTo(kScreenWidth);
// make.height.mas_equalTo(kScreenHeight);
//
// }];
//
// [self.imageV layoutIfNeeded];
}
}
#pragma mark --- 点击事件
-(void)taskButtonClickEvent{
[self setUpBackView];
CABasicAnimation *animationScale = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
animationScale.duration = 0.2;
animationScale.repeatCount = 1;
animationScale.fromValue = @0.0;
animationScale.toValue = @1.0;
animationScale.removedOnCompletion = NO;
animationScale.delegate = self;
CGRect frame = self.backView.frame;
/*定点缩放的位置 锚点 如果(0,0)就是从左上角缩放,如果 (1,1)就是从右下角 */
self.backView.layer.anchorPoint = CGPointMake(0.9, 0.9);
self.backView.frame = frame;
[self.backView.layer addAnimation:animationScale forKey:@"scale-show-layer"];
__weak typeof(self) weakSelf = self;
[UIView animateWithDuration:0.2 animations:^{
weakSelf.backView.alpha = 1;
}];
}
-(void)backViewClickEvent{
/*
fromValue:开始帧
toValue:结束帧
removedOnCompletion:设置是否自动移除动画
fillMode:设置保存动画状态
-> kCAFillModeForwards:保持着动画结束后状态(removedOnCompletion = NO)
-> kCAFillModeBackwards:回到动画开始前状态(removedOnCompletion = NO)
-> kCAFillModeBoth:上面两个的合成
-> kCAFillModeRemoved:默认值 动画开始或结束都会回到最初状态
*/
CABasicAnimation *animationScale = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
animationScale.duration = 0.2;
animationScale.repeatCount = 1;
animationScale.fromValue = @1.0;
animationScale.toValue = @0.0;
animationScale.fillMode = kCAFillModeBoth;
animationScale.removedOnCompletion = NO;
animationScale.delegate = self;
[self.backView.layer addAnimation:animationScale forKey:@"scale-remove-layer"];
__weak typeof(self) weakSelf = self;
[UIView animateWithDuration:0.2 animations:^{
weakSelf.backView.alpha = 0;
} completion:^(BOOL finished) {
[weakSelf.imageV removeFromSuperview];
weakSelf.imageV = nil;
[weakSelf.backView removeFromSuperview];
weakSelf.backView = nil;
}];
}
-(void) animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
if ([anim isEqual:[self.backView.layer animationForKey:@"scale-show-layer"]]) {
[self.backView.layer removeAnimationForKey:@"scale-show-layer"];
}else if ([anim isEqual:[self.backView.layer animationForKey:@"scale-remove-layer"]]){
[self.backView.layer removeAnimationForKey:@"scale-remove-layer"];
[self.backView removeFromSuperview];
}
}
@end
ios 定点缩放动画
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 效果图: 类似这样的弹窗,在APP中很常见,接下来说一下 实现思路: 1.点击弹出按钮时,阴影alpha由0到1,...
- 我这里是封装的一个单独的UIScrollView,用在制作相册的时候使用。 双指缩放代码 双击定点放大代码 这样就...
- iOS 一款可绕指定点旋转、缩放的多功能贴纸 支持双指手势操作,单指移动控制图操作,满足你所有需求 先上效果图: ...
- 前面提到过CALayer的anchorPoint和position对CABasicAnimation的动画过程会有...