1、新建视图控制器ImageViewController(不带xib),作为根视图控制器,ImageViewController.h如下:
#importImageViewController.m如下:@interface ImageViewController : UIViewController @property(strong,nonatomic)UIImageView *imageView; @property(strong,nonatomic)UIImage *desktop; -(void)loadImage; @end
#import "ImageViewController.h" @implementation ImageViewController @synthesize imageView; @synthesize desktop; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)loadView { // If you create your views manually, you MUST override this method and use it to create your views. // If you use Interface Builder to create your views, then you must NOT override this method. NSLog(@"loadView"); UIView *view = [[ UIView alloc] initWithFrame:[ UIScreen mainScreen].applicationFrame] ; UIColor *bgColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1.0]; [view setBackgroundColor:(bgColor)]; self.view = view; desktop = [UIImage imageNamed:@"desktop.png"]; [self performSelector:@selector(loadImage) withObject:nil afterDelay:0.1]; } -(void)loadImage{ if(imageView!=nil){ [imageView removeFromSuperview]; } //初始时,将imageView的宽度设置为0,这样就隐藏起来了 imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 0, desktop.size.height)]; [imageView setImage:desktop]; [self.view addSubview:imageView]; //设置动画效果 CGContextRef context = UIGraphicsGetCurrentContext(); //开始播放动画 [UIView beginAnimations:nil context:context]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; //[UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; //[UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; //[UIView setAnimationCurve:UIViewAnimationCurveLinear]; [UIView setAnimationDuration:1.5]; //imageView最终的宽度为desktop.size.width [imageView setFrame:CGRectMake(0, 0, desktop.size.width, desktop.size.height)]; [UIView commitAnimations]; } -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [self loadImage]; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. imageView = nil; desktop = nil; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait); } @end2、运行效果是图片从左至右慢慢显示出来,如下,
收藏的用户(0) X
正在加载信息~
推荐阅读
最新回复 (0)
站点信息
- 文章2305
- 用户1336
- 访客11381927
每日一句
Great people do things before they are ready.
伟大的人在准备好前就行动。
伟大的人在准备好前就行动。
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is
Android 8.0应用图标适配
解决vue动态生成el-table-column按钮点击事件
VC++实现远程控制
傻瓜式安装黑苹果的方式,超简单,吐血推荐!
Android最简单方式实现DatePickerDialog只显示年、月、日
mysql查询表索引的命令使用小记
Mac OS解决开机黑屏时间长(秒启动)
使用HTML和CSS设计磨砂玻璃效果
简单利用Clover四叶草安装U盘安装黑苹果
font-awesome-to-png快速将Font-Awesome字体保存为PNG图片
2017年10月编程语言排行榜
XPosed插件自动生成支付宝收款二维码
新会员