淡入淡出UIView动画

因为最近在忙个项目,所以有一段时间没更新博客了


好,直奔主题:

先在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;
        }];
    }
}

最后,大功告成


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值