美文网首页iOS开发
iOS---界面的淡入淡出效果

iOS---界面的淡入淡出效果

作者: lizhi_boy | 来源:发表于2017-03-16 15:38 被阅读2061次

    简单的界面淡入淡出的效果--------主要的实现思路是改变界面的透明度

    - (void)viewDidLoad {
        [super viewDidLoad];
        
        //要弹出的界面
        UIView *testView = [[UIView alloc] initWithFrame:self.view.frame];
        testView.backgroundColor = [UIColor blueColor];
        testView.tag = 1000;
        [self.view addSubview:testView];
        testView.alpha = 0.0;
     
        //创建当前界面点击手势
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(test)];
        [self.view addGestureRecognizer:tap];
    
        //创建淡出界面的点击手势
         UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(test2)];
        [testView addGestureRecognizer:tap2];
        
    }
    

    实现方法

    - (void)test{
    
        //改变透明度即可实现效果
        [UIView animateWithDuration:0.5 animations:^{
           UIView *view = [self.view viewWithTag:1000];
            view.alpha = 1.0;
            [self.view layoutIfNeeded];
        }];
        
    }
    
    - (void)test2{
        
        [UIView animateWithDuration:0.5 animations:^{
            UIView *view = [self.view viewWithTag:1000];
            view.alpha = 0.0;
            [self.view layoutIfNeeded];
        }];
        
    }
    

    还有一种最简单的方式是:

       [UIView transitionWithView:self.view duration:0.5 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
            self.view.backgroundColor = [UIColor redColor];
        } completion:nil];
    

    相关文章

      网友评论

        本文标题:iOS---界面的淡入淡出效果

        本文链接:https://www.haomeiwen.com/subject/uerjnttx.html