首页 > 移动平台 > 详细

ios遮罩层的简单使用

时间:2017-08-23 09:16:04      阅读:545      评论:0      收藏:0      [点我收藏+]

技术分享

/** 大图 */
- (IBAction)bigImg {
    //1.添加按钮遮罩层
    UIButton *cover=[[UIButton alloc] init];
    cover.frame=self.view.bounds;
    cover.backgroundColor=[UIColor blackColor];
    cover.alpha=0.0;
    [cover addTarget:self action:@selector(smallImg) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:cover];
    self.cover=cover;
    //2.更新阴影和头像的位置
    [self.view bringSubviewToFront:self.iconImage];
    
    //[UIView beginAnimations:nil context:nil];
    //执行动画遮罩层慢慢显示
    [UIView animateWithDuration:1.0 animations:^{
        cover.alpha=0.7;//设置透明度
        CGFloat iconW=self.view.frame.size.width;
        CGFloat iconH=iconW;
        CGFloat iconX=0;
        CGFloat iconY=(self.view.frame.size.height-iconH)*0.5;
        //CGRect myframe=self.iconImage.frame;
        self.oldRect=self.iconImage.frame;
        self.iconImage.frame=CGRectMake(iconX, iconY, iconW, iconH);
    }];
    
    //[UIView commitAnimations];
}
/** 小图 */
- (IBAction)smallImg{
    [UIView animateWithDuration:1.0 animations:^{
        //1.需要执行动画的代码
        //1.1缩回图标
        self.iconImage.frame=self.oldRect;
        self.cover.alpha=0.0;
    } completion:^(BOOL finished) {
        //2动画完成后执行的代码
        //2.1清除阴影
        [self.cover removeFromSuperview];
        self.cover=nil;
    }];
}

 

ios遮罩层的简单使用

原文:http://www.cnblogs.com/zqrios/p/7415519.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!