ios UIView animateWithDuration 学习

来源:互联网 发布:手机通讯录编辑软件 编辑:程序博客网 时间:2024/05/16 15:07

以下代码实现的效果:下滑到某一高度后自动隐藏掉

原始效果1


原始效果2  慢慢的下滑



原始效果3 隐藏消失


#pragma mark -- UIView animateWithDuration- (void)initTestBtn{    _testBtn = [[UIButton alloc]initWithFrame:CGRectMake(15, 230, kDEVICEWIDTH-30, 45)];    _testBtn.backgroundColor = [UIColor grayColor];    [_testBtn addTarget:self action:@selector(commitClick) forControlEvents:UIControlEventTouchUpInside];    [_testBtn setTitle:@"提交" forState:UIControlStateNormal];    _testBtn.titleLabel.textColor = [UIColor whiteColor];    _testBtn.layer.cornerRadius = 4;    [self.view addSubview:_testBtn];    //    _testView = [[UIView alloc]initWithFrame:CGRectMake(15, 300, kDEVICEWIDTH-30, 45)];//    _testView.backgroundColor = [UIColor grayColor];//    //    [self.view addSubview:_testView];       // [_testView addSubview:_testBtn];}- (void)testAnimateWithDuration{    /*typeof(self) 是获取到self的类型,这样定义出的weakSelf就是和self一个类型的, 加上__weak是建立一个若引用,整句就是给self定义了一个若引用性质的替身;    这个一般用在使用block时会用到,因为block会copy它内部的变量,可能会造成引用循环,使用__weak性质的self替代self,可以切断block对self的引用,避免循环引用*/    __weak __typeof(self) weakSelf = self;        CGRect _tempCG = _testBtn.frame;        _tempCG.origin.y = 360;        [UIView animateWithDuration:1.5                     animations:^{                                                  //_testBtn.frame = CGRectMake(15, kDEVICEHEIGHT, kDEVICEWIDTH-30, 45);                                                  _testBtn.frame = _tempCG;                     }                     completion:^(BOOL finished)                     {                         _testBtn.hidden = YES;                     }];}


0 0
原创粉丝点击