淡入淡出UIView动画
2014-01-14 11:12
274 查看
因为最近在忙个项目,所以有一段时间没更新博客了
好,直奔主题:
先在viewDidLoad里添加一个将要执行动画的UIView,下面的代码注意要先把这个UIView隐藏
在点击某个按钮的时候执行下面方法:
在timer的方法中执行消失动画:
最后,大功告成
好,直奔主题:
先在viewDidLoad里添加一个将要执行动画的UIView,下面的代码注意要先把这个UIView隐藏
//产生一个提示框 _remindLabel = [[UILabel alloc] initWithFrame:CGRectMake(75, 385, WIDTH_OF_LABEL, HEIGHT_OF_LABEL)]; self.remindLabel.backgroundColor = [UIColor clearColor]; [self.remindLabel setTextColor:[UIColor whiteColor]]; [self.remindLabel setFont:[UIFont systemFontOfSize:13.0]]; [self.view addSubview:self.remindLabel]; [self.view bringSubviewToFront:self.remindLabel]; self.remindLabel.hidden = YES; [_remindLabel release];
在点击某个按钮的时候执行下面方法:
- (void)downloadBtnFun { DNData *data = [DNData shareInstance]; int index = fabs(self.scrollView.contentOffset.x / self.view.bounds.size.width); ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; UIImage *image = [UIImage imageNamed:[data.imageArray objectAtIndex:index]]; [library writeImageToSavedPhotosAlbum:[image CGImage]orientation:ALAssetOrientationUp completionBlock:^(NSURL *url, NSError *error) { if (error) { self.remindLabel.text = @"图片存储失败"; } else { self.remindLabel.text = @"图片已存入相册"; } }]; if (self.remindLabel.hidden == YES) { self.remindLabel.hidden = NO; self.remindLabel.alpha = 0.3; [UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^ { self.remindLabel.alpha = 1.0; NSLog(@"in animate start"); } completion:^(BOOL finished) { NSLog(@"in animate completion"); }]; } self.timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(disappearLabel) userInfo:nil repeats:NO]; }
在timer的方法中执行消失动画:
- (void)disappearLabel { if (self.remindLabel.hidden == NO) { self.remindLabel.alpha = 1.0; [UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^ { self.remindLabel.alpha = 0.0; NSLog(@"out animate start"); }completion:^(BOOL finished) { NSLog(@"out animate completion"); if (self.timer) { [self.timer invalidate]; self.timer = nil; } self.remindLabel.hidden = YES; }]; } }
最后,大功告成
相关文章推荐
- ueditor单独调用上传附件和图片的功能
- USACO Section2.1 Sorting a Three-Valued Sequence
- A Proud Linguist
- postfix + dovecot + squirrelmail
- hibernate.QueryException: ClassNotFoundException: org.hibernate.hql.ast.HqlToken
- [leetcode]Unique Binary Search Trees
- GCD使用(二)执行与UI无关的操作
- 关于UIView的autoresizingMask属性的研究
- DuiLib如何禁用双击标题栏窗口最大化
- JS 获取 radio value的代码
- android_UI布局方法与工具
- 再谈select, iocp, epoll,kqueue及各种I/O复用机制
- 哈04-xcode系统自带的刷新控件UIRefreshControl
- CPUID HWMonitorV1.23 绿色中文版(测CPU温度)
- 哈02—kill error_______unable to dequeue a cell with identifier Cell
- HorizontalScrollView
- ScrollView
- uint8_t / uint16_t / uint32_t /uint64_t 的简单介绍
- 获取屏幕和组件高度宽度
- [leet code] Unique Paths