zoukankan      html  css  js  c++  java
  • 【代码笔记】iOS-淡出淡入效果

    一,效果图。

    二,工程图。

    三,代码.

    ViewController.h

    #import <UIKit/UIKit.h>
    
    @interface ViewController : UIViewController
    
    
    @end

     

    ViewController.m

    复制代码
    #import "ViewController.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        
        //UIView
        UIView *view=[[UIView alloc]initWithFrame:CGRectMake(10, 100, 200, 200)];
        view.backgroundColor=[UIColor redColor];
        [self.view addSubview:view];
        
        //淡出
        //[self fadeOut:view];
        
        //淡入
        //[self fadeIn:view];
        
    }
    
    //淡出
    -(void) fadeOut:(UIView *)view
    {
        CGContextRef context = UIGraphicsGetCurrentContext();
        [UIView beginAnimations:nil context:context];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:0.3];
        [view setAlpha:0.0f];
        [UIView commitAnimations];
    }
    
    //淡入
    -(void) fadeIn:(UIView *)view
    {
        CGContextRef context = UIGraphicsGetCurrentContext();
        [UIView beginAnimations:nil context:context];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:0.3];
        [view setAlpha:1.0f];
        [UIView commitAnimations];
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    复制代码

     

     

     
     
  • 相关阅读:
    如何用vue实现树形菜单?
    spring+springMVC,声明式事务失效,原因以及解决办法
    java提高同步锁的几点建议
    java自定义before和after
    java线程池
    jdk并发工具包之锁
    ReentrentLock重入锁
    java守护线程
    ReentrantLock
    java多线程基础
  • 原文地址:https://www.cnblogs.com/yang-guang-girl/p/5084640.html
Copyright © 2011-2022 走看看