成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

iPhone開(kāi)發(fā)中如何將制作圖片放大縮小代碼實(shí)現(xiàn)案例

移動(dòng)開(kāi)發(fā) iOS
iPhone開(kāi)發(fā)中如何將制作圖片放大縮小案例是本文要介紹的內(nèi)容,主要是來(lái)學(xué)習(xí)iphone開(kāi)發(fā)中動(dòng)畫(huà)的制作,具體內(nèi)容一起來(lái)看本文詳解。

iPhone開(kāi)發(fā)中如何將制作圖片放大縮小案例是本文要介紹的內(nèi)容,主要是來(lái)學(xué)習(xí)iphone開(kāi)發(fā)動(dòng)畫(huà)的制作,具體內(nèi)容一起來(lái)看本文詳解。在IPhone SDK開(kāi)發(fā)范例大全中,有很多的范例碼。

下面這段范例碼,示范了兩張圖片的交換,以及放大縮小的動(dòng)畫(huà)

動(dòng)畫(huà)效果請(qǐng)參照下圖

iPhone開(kāi)發(fā)中如何將制作圖片放大縮小代碼實(shí)現(xiàn)案例

  1. #import <UIKit/UIKit.h>     
  2.     
  3. #define IMAGE_VIEW_1    100     
  4. #define    IMAGE_VIEW_2    101     
  5.     
  6. #define BIGRECT CGRectMake(0.0f, 0.0f, 320.0f, 435.0f)     
  7. #define SMALLRECT CGRectMake(130.0f, 187.0f, 60.0f, 60.0f)      
  8.     
  9. @interface ToggleView: UIView    
  10. {    
  11.     BOOL isOne;    
  12. }    
  13. @end    
  14.     
  15. @implementation ToggleView    
  16.     
  17. - (id) initWithFrame: (CGRect) aFrame;    
  18. {    
  19.     self = [super initWithFrame:aFrame];    
  20.         
  21.     // Load both views, make them non-interactive     
  22.     UIImageView *imgView1 = [[UIImageView alloc] initWithFrame:BIGRECT];    
  23.     imgView1.image = [UIImage imageNamed:@"one.png"];    
  24.     imgView1.userInteractionEnabled = NO;    
  25.     imgView1.tag = IMAGE_VIEW_1;    
  26.     
  27.     UIImageView *imgView2 = [[UIImageView alloc] initWithFrame:SMALLRECT];    
  28.     imgView2.image = [UIImage imageNamed:@"two.png"];    
  29.     imgView2.userInteractionEnabled = NO;    
  30.     imgView2.tag = IMAGE_VIEW_2;    
  31.         
  32.     // image 1 is in front of image 2 to begin     
  33.     [self addSubview:imgView2];        
  34.     [self addSubview:imgView1];     
  35.     isOne = YES;    
  36.         
  37.     [imgView1 release];    
  38.     [imgView2 release];    
  39.     
  40.     return self;    
  41. }    
  42.     
  43. - (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event    
  44. {    
  45.     // Determine which view occupies which role     
  46.     UIImageView *big = (UIImageView *)[self viewWithTag: (isOne ? IMAGE_VIEW_1 : IMAGE_VIEW_2)];    
  47.     UIImageView *little = (UIImageView *)[self viewWithTag: (isOne ? IMAGE_VIEW_2 : IMAGE_VIEW_1)];    
  48.     isOne = !isOne;    
  49.         
  50.     // Pack all the changes into the animation block     
  51.     CGContextRef context = UIGraphicsGetCurrentContext();    
  52.     [UIView beginAnimations:nil context:context];    
  53.     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];    
  54.     [UIView setAnimationDuration:1.0];    
  55.     
  56.     [big setFrame:SMALLRECT];    
  57.     [big setAlpha:0.5];    
  58.     [little setFrame:BIGRECT];    
  59.     [little setAlpha:1.0];    
  60.         
  61.     [UIView commitAnimations];    
  62.         
  63.     // Hide the shrunken "big" image.     
  64.     [big setAlpha:0.0f];    
  65.     [[big superview] bringSubviewToFront:big];    
  66. }    
  67. @end    
  68.     
  69. @interface HelloController : UIViewController    
  70. @end    
  71.     
  72. @implementation HelloController    
  73. - (void)loadView    
  74. {    
  75.     ToggleView *contentView = [[ToggleView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];    
  76.     contentView.backgroundColor = [UIColor whiteColor];    
  77.     self.view = contentView;    
  78.     [contentView release];    
  79. }    
  80. @end    
  81.     
  82. @interface SampleAppDelegate : NSObject <UIApplicationDelegate>     
  83. @end    
  84.     
  85. @implementation SampleAppDelegate    
  86. - (void)applicationDidFinishLaunching:(UIApplication *)application {        
  87.     UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];    
  88.     HelloController *hello = [[HelloController alloc] init];    
  89.     [window addSubview:hello.view];    
  90.     [window makeKeyAndVisible];    
  91. }    
  92. @end    
  93.     
  94. int main(int argc, char *argv[])    
  95. {    
  96.     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];    
  97.     int retVal = UIApplicationMain(argc, argv, nil, @"SampleAppDelegate");    
  98.     [pool release];    
  99.     return retVal;    
  100. }    
  101. #import <UIKit/UIKit.h> 
  102.  
  103. #define IMAGE_VIEW_1    100  
  104. #define    IMAGE_VIEW_2    101  
  105.  
  106. #define BIGRECT CGRectMake(0.0f, 0.0f, 320.0f, 435.0f)  
  107. #define SMALLRECT CGRectMake(130.0f, 187.0f, 60.0f, 60.0f)   
  108.  
  109. @interface ToggleView: UIView  
  110. {  
  111.     BOOL isOne;  
  112. }  
  113. @end  
  114.  
  115. @implementation ToggleView  
  116.  
  117. - (id) initWithFrame: (CGRect) aFrame;  
  118. {  
  119.     self = [super initWithFrame:aFrame];  
  120.       
  121.     // Load both views, make them non-interactive  
  122.     UIImageView *imgView1 = [[UIImageView alloc] initWithFrame:BIGRECT];  
  123.     imgView1.image = [UIImage imageNamed:@"one.png"];  
  124.     imgView1.userInteractionEnabled = NO;  
  125.     imgView1.tag = IMAGE_VIEW_1;  
  126.  
  127.     UIImageView *imgView2 = [[UIImageView alloc] initWithFrame:SMALLRECT];  
  128.     imgView2.image = [UIImage imageNamed:@"two.png"];  
  129.     imgView2.userInteractionEnabled = NO;  
  130.     imgView2.tag = IMAGE_VIEW_2;  
  131.       
  132.     // image 1 is in front of image 2 to begin  
  133.     [self addSubview:imgView2];      
  134.     [self addSubview:imgView1];   
  135.     isOne = YES;  
  136.       
  137.     [imgView1 release];  
  138.     [imgView2 release];  
  139.  
  140.     return self;  
  141. }  
  142.  
  143. - (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event  
  144. {  
  145.     // Determine which view occupies which role  
  146.     UIImageView *big = (UIImageView *)[self viewWithTag: (isOne ? IMAGE_VIEW_1 : IMAGE_VIEW_2)];  
  147.     UIImageView *little = (UIImageView *)[self viewWithTag: (isOne ? IMAGE_VIEW_2 : IMAGE_VIEW_1)];  
  148.     isOne = !isOne;  
  149.       
  150.     // Pack all the changes into the animation block  
  151.     CGContextRef context = UIGraphicsGetCurrentContext();  
  152.     [UIView beginAnimations:nil context:context];  
  153.     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];  
  154.     [UIView setAnimationDuration:1.0];  
  155.     [big setFrame:SMALLRECT];  
  156.     [big setAlpha:0.5];  
  157.     [little setFrame:BIGRECT];  
  158.     [little setAlpha:1.0];  
  159.     [UIView commitAnimations];  
  160.     // Hide the shrunken "big" image.  
  161.     [big setAlpha:0.0f];  
  162.     [[big superview] bringSubviewToFront:big];  
  163. }  
  164. @end  
  165. @interface HelloController : UIViewController  
  166. @end  
  167. @implementation HelloController  
  168. - (void)loadView  
  169. {  
  170.     ToggleView *contentView = [[ToggleView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];  
  171.     contentView.backgroundColor = [UIColor whiteColor];  
  172.     self.view = contentView;  
  173.     [contentView release];  
  174. }  
  175. @end  
  176. @interface SampleAppDelegate : NSObject <UIApplicationDelegate>   
  177. @end  
  178. @implementation SampleAppDelegate  
  179. - (void)applicationDidFinishLaunching:(UIApplication *)application {      
  180.     UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];  
  181.     HelloController *hello = [[HelloController alloc] init];  
  182.     [window addSubview:hello.view];  
  183.     [window makeKeyAndVisible];  
  184. }  
  185. @end  
  186. int main(int argc, char *argv[])  
  187. {  
  188.     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];  
  189.     int retVal = UIApplicationMain(argc, argv, nil, @"SampleAppDelegate");  
  190.     [pool release];  
  191.     return retVal;  

最重要的動(dòng)畫(huà)代碼

  1. - (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event    
  2. {    
  3.     // 這一段代碼,設(shè)定目前哪一張圖是大圖,哪一張是小圖     
  4.     UIImageView *big = (UIImageView *)[self viewWithTag: (isOne ? IMAGE_VIEW_1 : IMAGE_VIEW_2)];    
  5.     UIImageView *little = (UIImageView *)[self viewWithTag: (isOne ? IMAGE_VIEW_2 : IMAGE_VIEW_1)];    
  6.     isOne = !isOne;    
  7.         
  8.     // 這是使用動(dòng)畫(huà)的一些基本設(shè)定     
  9.     CGContextRef context = UIGraphicsGetCurrentContext();    
  10.     [UIView beginAnimations:nil context:context];    
  11.     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; // 設(shè)定為IN OUT的動(dòng)畫(huà)     
  12.     [UIView setAnimationDuration:1.0]; // 動(dòng)畫(huà)時(shí)間為一秒     
  13.     
  14.     [big setFrame:SMALLRECT];    
  15.     [big setAlpha:0.5];    
  16.     [little setFrame:BIGRECT];    
  17.     [little setAlpha:1.0];    
  18.         
  19.     [UIView commitAnimations];    
  20.         
  21.     // Hide the shrunken "big" image.     
  22.     [big setAlpha:0.0f];    
  23.     [[big superview] bringSubviewToFront:big];    
  24. }    
  25. @end    
  26. - (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event  
  27. {  
  28.  // 這一段代碼,設(shè)定目前哪一張圖是大圖,哪一張是小圖  
  29.  UIImageView *big = (UIImageView *)[self viewWithTag: (isOne ? IMAGE_VIEW_1 : IMAGE_VIEW_2)];  
  30.  UIImageView *little = (UIImageView *)[self viewWithTag: (isOne ? IMAGE_VIEW_2 : IMAGE_VIEW_1)];  
  31.  isOne = !isOne;  
  32.    
  33.  // 這是使用動(dòng)畫(huà)的一些基本設(shè)定  
  34.  CGContextRef context = UIGraphicsGetCurrentContext();  
  35.  [UIView beginAnimations:nil context:context];  
  36.  [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; // 設(shè)定為IN OUT的動(dòng)畫(huà)  
  37.  [UIView setAnimationDuration:1.0]; // 動(dòng)畫(huà)時(shí)間為一秒  
  38.  
  39.  [big setFrame:SMALLRECT];  
  40.  [big setAlpha:0.5];  
  41.  [little setFrame:BIGRECT];  
  42.  [little setAlpha:1.0];  
  43.    
  44.  [UIView commitAnimations];  
  45.    
  46.  // Hide the shrunken "big" image.  
  47.  [big setAlpha:0.0f];  
  48.  [[big superview] bringSubviewToFront:big];  
  49. }  
  50. @end  

iPhone開(kāi)發(fā)中如何將制作圖片放大縮小代碼實(shí)現(xiàn)案例

代碼中設(shè)定透明度的目的,為了就是小圖放大的時(shí)候,才不會(huì)被原本在上面的大圖蓋到,導(dǎo)致看不到圖。

小結(jié):iPhone開(kāi)發(fā)中如何將制作圖片放大縮小案例的內(nèi)容介紹完了,希望通過(guò)本文的學(xué)習(xí)能對(duì)你有所幫助!

責(zé)任編輯:zhaolei 來(lái)源: CSDN博客
相關(guān)推薦

2011-08-15 15:44:46

iPhone開(kāi)發(fā)PDF

2011-08-18 16:24:44

iPhone開(kāi)發(fā)圖片

2011-08-16 15:48:37

iPhone開(kāi)發(fā)抓圖程序

2011-08-19 10:05:30

iPhone開(kāi)發(fā)

2011-08-18 16:03:34

iPhone上傳圖片

2011-08-18 16:42:07

iPhone應(yīng)用APNS推送

2011-08-18 15:40:20

iPhone文本切頁(yè)

2011-08-15 11:23:41

iPhone開(kāi)發(fā)循環(huán)滾動(dòng)UIScrollVie

2011-08-09 14:54:29

iPhoneNSDateanotherDate

2010-01-21 14:13:48

VB.NET制作圖片按

2011-07-08 15:08:16

iPhone 圖片

2011-08-19 11:10:31

iPhone應(yīng)用

2011-08-19 10:13:05

iPhone開(kāi)發(fā)

2020-08-12 09:14:45

Python驗(yàn)證碼工具

2017-05-03 16:36:32

Android圖片動(dòng)畫(huà)

2011-08-10 14:40:23

iPhone動(dòng)畫(huà)

2011-07-27 11:19:33

iPhone UITableVie

2011-08-16 14:54:12

iphone開(kāi)發(fā)APP

2011-08-18 15:24:40

iPhone國(guó)際化

2011-08-19 11:03:37

iPhone應(yīng)用三軸感應(yīng)器
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)

主站蜘蛛池模板: 最新中文字幕久久 | 黄色片视频 | 成人av在线播放 | 国产精品久久久久久婷婷天堂 | 欧美一级黄色免费看 | 成人免费视频久久 | 久久国产精品免费一区二区三区 | 精品日韩一区二区 | 久久国产欧美日韩精品 | 中文字幕在线看第二 | 中文字幕成人av | 欧美视频一区二区三区 | h视频在线看 | 亚洲免费在线观看 | 黄a免费网络 | 黄色永久免费 | 欧美13videosex性极品 | 欧美午夜视频 | 欧美日韩国产精品一区 | 亚洲精品视频免费观看 | 中文天堂在线观看 | 伊人超碰| 久久精品一区二区三区四区 | 污视频免费在线观看 | 国产一区二区三区免费观看视频 | 亚洲黄色片免费观看 | 国产视频一区在线观看 | 欧产日产国产精品99 | 欧美专区日韩 | 一呦二呦三呦国产精品 | 99国产精品视频免费观看一公开 | 国产日韩精品久久 | 国产精品久久久久久婷婷天堂 | 欧美一区二区 | 婷婷福利视频导航 | av看片网站 | 亚洲精品成人网 | 激情五月激情综合网 | 欧美一级在线视频 | 91视频观看 | 99精品久久99久久久久 |