@[toc]浏览器
iOS开发中经常使用的动画(定点缩放弹窗)的应用场景:markdown
一、会员详情的右侧下拉操做菜单oop
二、浏览器的右侧下拉菜单
动画
demo下载地址:https://download.csdn.net/download/u011018979/16092830ui
每个UIView内部都默认关联着一个CALayer, UIView有frame、bounds和center三个属性,CALayer也有相似的属性,分别为frame、bounds、position、anchorPointspa
anchorPoint就至关于白纸上的图钉,它主要的做用就是用来做为变换的支点,旋转就是一种变换,相似的还有平移、缩放。.net
在iOS中,anchorPoint点的值是用一种相对bounds的比例值来肯定的,在白纸的左上角、右下角,anchorPoint分为为(0,0), (1, 1),也就是说anchorPoint是在单元坐标空间(同时也是左手坐标系)中定义的。相似地,能够得出在白纸的中心点、左下角和右上角的anchorPoint为(0.5,0.5), (0,1), (1,0)。3d
position是layer中的anchorPoint点在superLayer中的位置坐标。code
position点是相对suerLayer的,anchorPoint点是相对layer的,二者是相对不一样的坐标空间的一个重合点。orm
修改anchorPoint,但又不想要移动layer也就是不想修改frame.origin,那么根据前面的公式,就须要position作相应地修改。简单地推导,能够获得下面的公式:
positionNew.x = positionOld.x + (anchorPointNew.x - anchorPointOld.x) * bounds.size.width
positionNew.y = positionOld.y + (anchorPointNew.y - anchorPointOld.y) * bounds.size.height
复制代码
修改anchorPoint而不想移动layer,在修改anchorPoint后再从新设置一遍frame就能够达到目的,这时position就会自动进行相应的改变。
+ (void) setAnchorPoint:(CGPoint)anchorpoint forView:(UIView *)view{
CGRect oldFrame = view.frame;
view.layer.anchorPoint = anchorpoint;
view.frame = oldFrame;
}
复制代码
/* (0,0) 为左上角,(0,1) 为左下角, (1, 0)右上, (1,1) 右下 */
CGRect oldFrame = self.frame ;
[self.layer setAnchorPoint: CGPointMake(1.0f, 0.0f) ];
self.frame = oldFrame;
[UIView animateWithDuration:0.3 animations:^{
// self.alpha = 0.f;
// self.tableView.transform = CGAffineTransformMakeScale(0.001f, 0.001f);
self.transform = CGAffineTransformMakeScale(0.001f, 0.001f);
// self.tableView.alpha = 0.f;
self.cover.hidden = YES;
} completion:^(BOOL finished) {
self.hidden = YES;
self.transform = CGAffineTransformIdentity;
}];
复制代码
/** 一、点击弹出按钮时,阴影alpha由0到1,弹窗的scale由0到1(这里使用CABasicAnimation) 二、 点击空白处,再让阴影alpha由1到0,弹窗的scale由1到0(一样使用CABasicAnimation),动画完成后移除阴影和弹窗 */
- (void)expandView{
//展现的时候,动画从右上角往左下脚延伸;隐藏的时候,动画从左下脚往右上角收回
[MemberCardMenuView setAnchorPoint:CGPointMake(0.9f, 0.0f) forView:self];
self.transform = CGAffineTransformMakeScale(0.001f, 0.001f);
self.hidden = NO;// 修改成动画, MemberCardMenuView 提供一个动画的实例方法
self.cover.hidden = NO;
self.cover.alpha = 0;
[UIView animateWithDuration:0.3 animations:^{
self.transform = CGAffineTransformMakeScale(1.f, 1.f);
self.cover.alpha = 1;
} completion:^(BOOL finished) {
self.transform = CGAffineTransformIdentity;
}];
}
- (void)foldView{
/* (0,0) 为左上角,(0,1) 为左下角, (1, 0)右上, (1,1) 右下 */
[UIView animateWithDuration:0.3 animations:^{
self.transform = CGAffineTransformMakeScale(0.001f, 0.001f);
self.cover.alpha = 0;
} completion:^(BOOL finished) {
self.hidden = YES;
self.cover.hidden = YES;
self.transform = CGAffineTransformIdentity;
}];
}
复制代码
iOS开发中经常使用的动画(定点缩放弹窗)的应用场景:
一、会员详情的右侧下拉操做菜单
二、浏览器的右侧下拉菜单
三、demo下载地址:https://download.csdn.net/download/u011018979/16092830