【代码笔记】iOS-淡出淡入效果

来源:互联网 发布:彩虹易支付源码 编辑:程序博客网 时间:2024/06/03 20:10

一,效果图。

二,工程图。

三,代码.

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.}
复制代码

 


0 0
原创粉丝点击