imageVIew自带的动画效果(类似TOM…
2014-11-17 16:26
253 查看
//
// AppDelegate.m
//
不会说话的汤姆猫
//
// Created by qianfeng on 14-8-27.
// Copyright (c) 2014年
xuli. All rights reserved.
//
#import "AppDelegate.h"
@implementation AppDelegate
-(void)dealloc
{
[self.window release];
[super dealloc];
}
-(void)createImageView
{
//首先创建一个UIImageView的对象
UIImageView *
imageView = [[UIImageView alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
//imageView.image =[UIImage
imageNamed:@""];
//如果图片所占内存比较大
用以上方法添加的图片会发存放在应用程序中 占用系统的活跃内存
系统的活跃内存是有限的 所以存放图片如果很大 不建议使用以上方法
//NSBundle 路径类
//[NSBundle mainBundle] 获取的是当前工程的路径
//pathForResource:获取某个资源
第一个参数添加的是查找的资源的名称 第二个参数是资源的后缀名
NSString *
path = [[NSBundle
mainBundle]
pathForResource:@"cat_eat0000" ofType:@"jpg"];
//每次使用的图片的时候都会直接到路径下获取
然后不存放在活跃内存中 虽然效率很低 但是很安全 不会因为获取内存不足报警告
或程序崩溃
UIImage * image1 = [UIImage imageWithContentsOfFile:path];
imageView.image = image1;
NSMutableArray * arr = [[NSMutableArray alloc]init];
//将所有图片添加到数组里
for(int
i = 0;i<<span
style="color: #272ad8">40;i++)
{
NSString *
string = [[NSBundle
mainBundle]
pathForResource:[NSString stringWithFormat:@"cat_eat00%.2d",i] ofType:@"jpg"];
UIImage *
image = [UIImage imageWithContentsOfFile:string];
[arr addObject:image];
}
[self.window addSubview:imageView];
//当前的imageView与用户进行交互
imageView.userInteractionEnabled = YES;
//UIImageVeiw 与UILabel
都是不能与用户交互
所以要将userInteractionEnabled设为yes以后才可进行交互
//1、为当前的imageView
添加一组图片(数组中存放的就是图片的对象指针)
[imageView setAnimationImages:arr];
//2、动画时间
[imageView setAnimationDuration:3];
//3、设置动画的显示次数(-1表示无限循环)
[imageView setAnimationRepeatCount:-1];
//4、动画开始
[imageView startAnimating];
//5、动画停止的方法
//点击手势类
UITapGestureRecognizer * tap = [[UITapGestureRecognizer
alloc]initWithTarget:self
action:@selector(stop:)];
//设置点击的次数
tap.numberOfTapsRequired = 1;
//几根手指点击
tap.numberOfTouchesRequired = 2;
//将点击事件添加到imageView上
[imageView addGestureRecognizer:tap];
}
-(void)stop:(UITapGestureRecognizer * )recognizer
{
//通过手势
查找添加了手势的视图
[((UIImageView *)recognizer.view) stopAnimating];
//stopAnimating停止动画
}
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window
= [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after
application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self
createImageView];
[self.window
makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication
*)application
{
// Sent when the application is about to
move from active to inactive state. This can occur for certain
types of temporary interruptions (such as an incoming phone call or
SMS message) or when the user quits the application and it begins
the transition to the background state.
// Use this method to pause ongoing
tasks, disable timers, and throttle down OpenGL ES frame rates.
Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication
*)application
{
// Use this method to release shared
resources, save user data, invalidate timers, and store enough
application state information to restore your application to its
current state in case it is terminated later.
// If your application supports
background execution, this method is called instead of
applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication
*)application
{
// Called as part of the transition from
the background to the inactive state; here you can undo many of the
changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication
*)application
{
// Restart any tasks that were paused (or
not yet started) while the application was inactive. If the
application was previously in the background, optionally refresh
the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about
to terminate. Save data if appropriate. See also
applicationDidEnterBackground:.
}
@end
// AppDelegate.m
//
不会说话的汤姆猫
//
// Created by qianfeng on 14-8-27.
// Copyright (c) 2014年
xuli. All rights reserved.
//
#import "AppDelegate.h"
@implementation AppDelegate
-(void)dealloc
{
[self.window release];
[super dealloc];
}
-(void)createImageView
{
//首先创建一个UIImageView的对象
UIImageView *
imageView = [[UIImageView alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
//imageView.image =[UIImage
imageNamed:@""];
//如果图片所占内存比较大
用以上方法添加的图片会发存放在应用程序中 占用系统的活跃内存
系统的活跃内存是有限的 所以存放图片如果很大 不建议使用以上方法
//NSBundle 路径类
//[NSBundle mainBundle] 获取的是当前工程的路径
//pathForResource:获取某个资源
第一个参数添加的是查找的资源的名称 第二个参数是资源的后缀名
NSString *
path = [[NSBundle
mainBundle]
pathForResource:@"cat_eat0000" ofType:@"jpg"];
//每次使用的图片的时候都会直接到路径下获取
然后不存放在活跃内存中 虽然效率很低 但是很安全 不会因为获取内存不足报警告
或程序崩溃
UIImage * image1 = [UIImage imageWithContentsOfFile:path];
imageView.image = image1;
NSMutableArray * arr = [[NSMutableArray alloc]init];
//将所有图片添加到数组里
for(int
i = 0;i<<span
style="color: #272ad8">40;i++)
{
NSString *
string = [[NSBundle
mainBundle]
pathForResource:[NSString stringWithFormat:@"cat_eat00%.2d",i] ofType:@"jpg"];
UIImage *
image = [UIImage imageWithContentsOfFile:string];
[arr addObject:image];
}
[self.window addSubview:imageView];
//当前的imageView与用户进行交互
imageView.userInteractionEnabled = YES;
//UIImageVeiw 与UILabel
都是不能与用户交互
所以要将userInteractionEnabled设为yes以后才可进行交互
//1、为当前的imageView
添加一组图片(数组中存放的就是图片的对象指针)
[imageView setAnimationImages:arr];
//2、动画时间
[imageView setAnimationDuration:3];
//3、设置动画的显示次数(-1表示无限循环)
[imageView setAnimationRepeatCount:-1];
//4、动画开始
[imageView startAnimating];
//5、动画停止的方法
//点击手势类
UITapGestureRecognizer * tap = [[UITapGestureRecognizer
alloc]initWithTarget:self
action:@selector(stop:)];
//设置点击的次数
tap.numberOfTapsRequired = 1;
//几根手指点击
tap.numberOfTouchesRequired = 2;
//将点击事件添加到imageView上
[imageView addGestureRecognizer:tap];
}
-(void)stop:(UITapGestureRecognizer * )recognizer
{
//通过手势
查找添加了手势的视图
[((UIImageView *)recognizer.view) stopAnimating];
//stopAnimating停止动画
}
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window
= [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after
application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self
createImageView];
[self.window
makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication
*)application
{
// Sent when the application is about to
move from active to inactive state. This can occur for certain
types of temporary interruptions (such as an incoming phone call or
SMS message) or when the user quits the application and it begins
the transition to the background state.
// Use this method to pause ongoing
tasks, disable timers, and throttle down OpenGL ES frame rates.
Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication
*)application
{
// Use this method to release shared
resources, save user data, invalidate timers, and store enough
application state information to restore your application to its
current state in case it is terminated later.
// If your application supports
background execution, this method is called instead of
applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication
*)application
{
// Called as part of the transition from
the background to the inactive state; here you can undo many of the
changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication
*)application
{
// Restart any tasks that were paused (or
not yet started) while the application was inactive. If the
application was previously in the background, optionally refresh
the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about
to terminate. Save data if appropriate. See also
applicationDidEnterBackground:.
}
@end
相关文章推荐
- Android UI:看看Google官方自定义带旋转动画的ImageView-----RotateImageView怎么写(附 图片淡入淡出效果)
- uitable view自带的动画效果
- Android进阶:实现android系统自带查看照片动画效果 类似Gallery手势滑动
- Android使用PowerImageView实现播放强大的ImageView动画效果
- Android UI:看看Google官方自定义带旋转动画的ImageView-----RotateImageView怎么写(附 图片淡入淡出效果)
- AndroidRichText 让Textview轻松的支持富文本(图像ImageSpan、点击效果等等类似QQ微信聊天)
- 自定义ImageView实现类似微信朋友圈发图片点击出来阴影效果;同时使用Picasso加载网络图片
- ImageView增加动画效果
- android google 自带的下拉刷新 类似nice的加载数据动画效果
- [转]Android UI:看看Google官方自定义带旋转动画的ImageView-----RotateImageView怎么写(附 图片淡入淡出效果)
- android imageview按钮按下动画效果
- ui控件之UIImageView(imageView的动画效果)
- IOS自带view动画效果
- 156 UIImageView 和 CADisplayLink 实现 Tom 汤姆猫动画效果的区别(扩展知识:分组(黄色文件夹)和文件夹引用(蓝色文件夹)区别)
- 自定义view 类似QQ好友来消息的动画效果
- Android编程实现ImageView图片抛物线动画效果的方法
- 基于VerticalViewPager的上下滑动,可带动画效果,类似WheelView
- Android进阶——自定义View之继承系统控件实现自带删除按钮动画效果和软键盘自动悬浮于文本框下方
- Android RichText 让Textview轻松的支持富文本(图像ImageSpan、点击效果等等类似QQ微信聊天)
- IOS动画实现(2)ImageView自带动画