iOS动画 跳转菜单栏

     今天整理的动画效果如下图:
屏幕快照 2016-12-20 下午4.23.57.png

做这个小动画先要准备好一个小工具UIView+categroy;里面要设置好:X,Y,width,height,centerX,centerY,size,origin。
然后要新建两个ViewController,一个给动画发生,另一个作为跳转后的落脚页面。
下面是简要的代码和总结。

//
// ViewController.m
// 666
//
// Created by 李昊林 on 2016/12/20.
// Copyright © 2016年 李昊林. All rights reserved.
//

import "ViewController.h"

import "AViewController.h"

@interface ViewController ()

@end

@implementation ViewController

  • (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self.view setBackgroundColor:[UIColor cyanColor]];

}

  • (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {

    AViewController *A = [AViewController new];

    [self presentViewController:A animated:NO completion:^{
    [self removeFromParentViewController];
    }];
    }

//- (void)didReceiveMemoryWarning {
// [super didReceiveMemoryWarning];
// // Dispose of any resources that can be recreated.
//}

@end

项目总结:
1.在这个项目中-----在要跳转的控制器中的ViewDidLoad中去设置[UIView Animationg...动画效果是没有用的。 因为在跳转到这个控制器的某一个时刻已经执行了VDL 这一个时刻要么已经在VDL所在的作用域里面用完了。要么就失效了。

解决方法:
1.在ViewWillAppear中去布局控件,提前把所放量改成0.01
2.在viewDidAppear去执行动画操作,

2.注意点: 千万不要重写loadView的时候去什么都不做,,,要么去掉一个super 要么随便给它一个View
下面两句任选一: 推荐选第一句。

  • (void)loadView {
    // [super loadView];
    // self.view = [UIView new];

}

  1. 要构造一个和绘图有关的btn 创建一个Btn类的时候其实已经有了系统默认的drawRect方法:

  2. 在drawrect的方法中画圆,ARCCenter参数指的是drawRect方法从属的空间的frame上的位置。

5.之前的一个思想误区:
自定义btn,并不是在initWithFrame:方法中去重新创建一个新的btn去返回这个btn,
而是在方法中去设置相应的属性,用self去掉对象方法。

6.设置锚点anchorPoint的作用就是来设置一个定点或者起始点,防止动画往两边延伸,或者是给动画一个定点。

//
// AViewController.m
// 666
//
// Created by 李昊林 on 2016/12/20.
// Copyright © 2016年 李昊林. All rights reserved.
//

import "AViewController.h"

import "AView.h"

import "PersonalViewController.h"

define KCENTERX [UIScreen mainScreen].bounds.size.width * 0.5 - 64

define KCENTERY [UIScreen mainScreen].bounds.size.height * 0.5 - 64

@interface AViewController ()
@property (nonatomic, strong)UIButton *centerBtn;
@property (nonatomic, strong)UIButton *leftBtn1;
@property (nonatomic, strong)UIButton *leftBtn2;
@property (nonatomic, strong)UIButton *leftBtn3;
@property (nonatomic, strong)UIButton *rightBtn1;
@property (nonatomic, strong)UIButton *rightBtn2;
@property (nonatomic, strong)UIButton *rightBtn3;
@property (nonatomic, strong)AView *aView;

@end

@implementation AViewController

//- (UIButton *)centerBtn {
//
// if (_centerBtn!=nil) {
// _centerBtn = [[UIButton alloc]init];
// }
// return _centerBtn;
//}

  • (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.view.backgroundColor = [UIColor cyanColor];
    [self setupBtn];

}

  • (void)viewDidAppear:(BOOL)animated {

    [super viewDidAppear:animated];

[UIView animateWithDuration:0.5 delay:0 usingSpringWithDamping:0.9 initialSpringVelocity:10 options:UIViewAnimationOptionLayoutSubviews animations:^{
    self.centerBtn.transform = CGAffineTransformMakeScale(1.0, 1.0);
    
} completion:^(BOOL finished) {
    
}];

[UIView animateWithDuration:0.5 delay:0.2 usingSpringWithDamping:0.4 initialSpringVelocity:2 options:UIViewAnimationOptionLayoutSubviews animations:^{
    self.leftBtn1.transform = CGAffineTransformMakeScale(1.0, 1.0);
    self.rightBtn1.transform = CGAffineTransformMakeScale(1.0, 1.0);
    
} completion:^(BOOL finished) {
    
}];
[UIView animateWithDuration:0.5 delay:0.3 usingSpringWithDamping:0.4 initialSpringVelocity:2 options:UIViewAnimationOptionLayoutSubviews animations:^{
    self.leftBtn2.transform = CGAffineTransformMakeScale(1.0, 1.0);
    self.rightBtn2.transform = CGAffineTransformMakeScale(1.0, 1.0);
    
} completion:^(BOOL finished) {
    
}];
[UIView animateWithDuration:0.5 delay:0.4 usingSpringWithDamping:0.4 initialSpringVelocity:2 options:UIViewAnimationOptionLayoutSubviews animations:^{
    self.leftBtn3.transform = CGAffineTransformMakeScale(1.0, 1.0);
    self.rightBtn3.transform = CGAffineTransformMakeScale(1.0, 1.0);
    
} completion:^(BOOL finished) {
    
}];

[UIView animateWithDuration:2.0 delay:0.3 usingSpringWithDamping:0.4 initialSpringVelocity:2 options:UIViewAnimationOptionLayoutSubviews animations:^{
    self.aView.transform = CGAffineTransformMakeScale(20, 20);
    
} completion:^(BOOL finished) {
    
}];

}

  • (void)viewDidLoad {
    [super viewDidLoad];

    [self.view setBackgroundColor:[UIColor clearColor]];

}

  • (void)setupBtn {

    //中间扩大的的圆形btn
    AView *aView = [[AView alloc]initWithFrame:CGRectMake(140, 300, 100, 100)];
    aView.transform = CGAffineTransformMakeScale(0.01, 0.01);
    [aView setBackgroundColor:[UIColor clearColor]];
    [self.view addSubview:aView];
    self.aView = aView;

    //中间btn
    UIButton *centerBtn = [[UIButton alloc]initWithFrame:CGRectMake(KCENTERX, KCENTERY, 128, 128)];
    [centerBtn setBackgroundImage:[UIImage imageNamed:@"501"] forState:UIControlStateNormal];
    [centerBtn addTarget:self action:@selector(nextTVC) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:centerBtn];
    self.centerBtn = centerBtn;

    //左3
    UIButton *leftBtn3 = [[UIButton alloc]initWithFrame:CGRectMake(KCENTERX, KCENTERY-168, 128, 128)];
    [leftBtn3 setBackgroundImage:[UIImage imageNamed:@"554"] forState:UIControlStateNormal];
    [self.view addSubview:leftBtn3];
    self.leftBtn3 = leftBtn3;
    //左2
    UIButton *leftBtn2 = [[UIButton alloc]initWithFrame:CGRectMake(KCENTERX-47, KCENTERY-88, 128, 128)];
    [leftBtn2 setBackgroundImage:[UIImage imageNamed:@"532"] forState:UIControlStateNormal];
    [self.view addSubview:leftBtn2];
    self.leftBtn2 = leftBtn2;
    //左右1
    UIButton *leftBtn1 = [[UIButton alloc]initWithFrame:CGRectMake(KCENTERX-94, KCENTERY, 128, 128)];
    [leftBtn1 setBackgroundImage:[UIImage imageNamed:@"504"] forState:UIControlStateNormal];
    [self.view addSubview:leftBtn1];
    self.leftBtn1 = leftBtn1;

    UIButton *rightBtn1 = [[UIButton alloc]initWithFrame:CGRectMake(KCENTERX+94, KCENTERY, 128, 128)];
    [rightBtn1 setBackgroundImage:[UIImage imageNamed:@"507"] forState:UIControlStateNormal];
    [self.view addSubview:rightBtn1];
    self.rightBtn1 = rightBtn1;

    //右2
    UIButton *rightBtn2 = [[UIButton alloc]initWithFrame:CGRectMake(KCENTERX+48, KCENTERY+84, 128, 128)];
    [rightBtn2 setBackgroundImage:[UIImage imageNamed:@"504"] forState:UIControlStateNormal];
    [self.view addSubview:rightBtn2];
    self.rightBtn2 = rightBtn2;
    //右三
    UIButton *rightBtn3 = [[UIButton alloc]initWithFrame:CGRectMake(KCENTERX, KCENTERY+168, 128, 128)];
    [rightBtn3 setBackgroundImage:[UIImage imageNamed:@"560"] forState:UIControlStateNormal];
    [self.view addSubview:rightBtn3];
    self.rightBtn3 = rightBtn3;

    //中间btn动画
    centerBtn.transform = CGAffineTransformMakeScale(0.01, 0.01);
    leftBtn1.transform = CGAffineTransformMakeScale(0.01, 0.01);
    leftBtn2.transform = CGAffineTransformMakeScale(0.01, 0.01);
    leftBtn3.transform = CGAffineTransformMakeScale(0.01, 0.01);
    rightBtn1.transform = CGAffineTransformMakeScale(0.01, 0.01);
    rightBtn2.transform = CGAffineTransformMakeScale(0.01, 0.01);
    rightBtn3.transform = CGAffineTransformMakeScale(0.01, 0.01);
    }

  • (void)nextTVC {

NSLog(@"nextTVC");

PersonalViewController *PVC = [[PersonalViewController alloc]init];


[UIView animateWithDuration:1 delay:0 usingSpringWithDamping:0.9 initialSpringVelocity:1 options:UIViewAnimationOptionLayoutSubviews animations:^{
    self.centerBtn.transform = CGAffineTransformMakeRotation(M_PI_2);
    self.leftBtn1.transform = CGAffineTransformMakeScale(0.01, 0.01);
    self.leftBtn2.transform = CGAffineTransformMakeScale(0.01, 0.01);
    self.leftBtn3.transform = CGAffineTransformMakeScale(0.01, 0.01);
    self.rightBtn1.transform = CGAffineTransformMakeScale(0.01, 0.01);
    self.rightBtn2.transform = CGAffineTransformMakeScale(0.01, 0.01);
    self.rightBtn3.transform = CGAffineTransformMakeScale(0.01, 0.01);
    self.aView.transform = CGAffineTransformMakeScale(0.01, 0.01);
    
} completion:^(BOOL finished) {
    
    [self presentViewController:PVC animated:NO completion:^{
        
    }];
}];

}

@end
1.在这个项目中-----在要跳转的控制器中的ViewDidLoad中去设置[UIView Animationg...动画效果是没有用的。 因为在跳转到这个控制器的某一个时刻已经执行了VDL 这一个时刻要么已经在VDL所在的作用域里面用完了。要么就失效了。

解决方法:
1.在ViewWillAppear中去布局控件,提前把所放量改成0.01
2.在viewDidAppear去执行动画操作,

2.注意点:  千万不要重写loadView的时候去什么都不做,,,要么去掉一个super  要么随便给它一个View
            下面两句任选一:  推荐选第一句。
        - (void)loadView {
             //  [super loadView];
           // self.view = [UIView new];

         }

3.  要构造一个和绘图有关的btn  创建一个Btn类的时候其实已经有了系统默认的drawRect方法:

//
// PersonalViewController.m
// 666
//
// Created by 李昊林 on 2016/12/20.
// Copyright © 2016年 李昊林. All rights reserved.
//

import "PersonalViewController.h"

import "AViewController.h"

define KCENTERX [UIScreen mainScreen].bounds.size.width * 0.5

define KCENTERY [UIScreen mainScreen].bounds.size.height * 0.5

@interface PersonalViewController ()
@property (nonatomic, strong)UIScrollView *SV;
@end

@implementation PersonalViewController

  • (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    UIButton *BackBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 10, 30, 30)];
    [BackBtn setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    [BackBtn addTarget:self action:@selector(Back:) forControlEvents:UIControlEventTouchUpInside];

UIScrollView *SV = [[UIScrollView alloc]initWithFrame:[UIScreen mainScreen].bounds];
SV.center = CGPointMake(KCENTERX, KCENTERY + 200);
SV.backgroundColor = [UIColor yellowColor];
[self.view addSubview:SV];
[self.view addSubview:BackBtn];
self.SV = SV;
[self setupSV];

}

  • (void)Back:(UIButton *)sender
    {
    [self presentViewController:[[AViewController alloc] init] animated:true completion:^{

    }];
    }

  • (void)setupSV {

    //分界的上部分View
    UIView *cyanView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width , KCENTERY - 200)];
    cyanView.backgroundColor = [UIColor cyanColor];
    [self.SV addSubview:cyanView];

    UIButton *centerBtn = [[UIButton alloc]initWithFrame:CGRectMake(KCENTERX-64, KCENTERY-265, 128, 128)];
    [centerBtn setBackgroundImage:[UIImage imageNamed:@"501"] forState:UIControlStateNormal];
    [centerBtn addTarget:self action:@selector(myProfile) forControlEvents:UIControlEventTouchUpInside];
    centerBtn.transform = CGAffineTransformMakeRotation(M_PI_2);
    [self.SV addSubview:centerBtn];

    //头像下面的label
    UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(190, 185, 180, 20) ];
    nameLabel.text = @"我的";
    nameLabel.textColor = [UIColor whiteColor];
    [self.SV addSubview:nameLabel];
    }

  • (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [UIView animateWithDuration:0.5 animations:^{
    self.SV.transform = CGAffineTransformMakeTranslation(0, -200);

    }];
    }

  • (void)viewDidLoad {
    [super viewDidLoad];

    [self.view setBackgroundColor:[UIColor cyanColor]];

}

  • (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

}

  • (void)myProfile {

}

@end

好了,此简书只为记录今天收获的一个特效页面,很酷炫的

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,425评论 4 361
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,058评论 1 291
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,186评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,848评论 0 204
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,249评论 3 286
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,554评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,830评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,536评论 0 197
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,239评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,505评论 2 244
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,004评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,346评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,999评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,060评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,821评论 0 194
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,574评论 2 271
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,480评论 2 267

推荐阅读更多精彩内容