IOS開(kāi)發(fā)實(shí)例 View實(shí)現(xiàn)動(dòng)畫(huà)效果
IOS開(kāi)發(fā)實(shí)例 View實(shí)現(xiàn)動(dòng)畫(huà)效果是本文要介紹的內(nèi)容,在ios應(yīng)用中,經(jīng)??梢钥吹揭粋€(gè)點(diǎn)擊一個(gè)按鈕,一個(gè)視圖漸漸彈出,在一點(diǎn)按鈕,視圖慢慢縮回去。這個(gè)動(dòng)畫(huà)效果在ios中經(jīng)常使用,下面是我寫(xiě)的一個(gè)小例子,界面效果如下:
 

具體的實(shí)現(xiàn)過(guò)程如下:
創(chuàng)建工程。
利用Interface Builder添加一個(gè)按鈕和一個(gè)視圖,把視圖底色換一個(gè)顏色。
在頭文件中進(jìn)行聲明:
- #import <UIKit/UIKit.h>
 - @interface ipad_scrollViewViewController : UIViewController {
 - IBOutlet UIButton *myButton;
 - UILabel *tableView;
 - IBOutlet UIView *myView;
 - }
 - @property(nonatomic,retain) UIButton *myButton;
 - @property(nonatomic,retain) UIView *myView;
 - -(IBAction)onClickButton:(id)sender;
 - @end
 - 把IB中的組件和相關(guān)對(duì)象相連接。
 - 實(shí)現(xiàn)具體的代碼:
 - #import "ipad_scrollViewViewController.h"
 - @implementation ipad_scrollViewViewController
 - @synthesize myButton,myView;
 - - (void)viewDidLoad {
 - [super viewDidLoad];
 - }
 - - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 - return YES;
 - }
 - - (void)didReceiveMemoryWarning {
 - [super didReceiveMemoryWarning];
 - }
 - - (void)viewDidUnload {
 - self.myButton=nil;
 - self.myView=nil;
 - }
 - - (void)dealloc {
 - [self.myView release];
 - [self.myButton release];
 - [super dealloc];
 - }
 - -(IBAction)onClickButton:(id)sender
 - {
 - CGContextRef context = UIGraphicsGetCurrentContext();
 - [UIView beginAnimations:@"Curl" context:context];
 - [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
 - [UIView setAnimationDuration:0.5];
 - CGRect rect = [myView frame];
 - CGRect rect1=[myButton frame];
 - if (rect.origin.x>0) {
 - rect.origin.x = 26.0f – rect.size.width;
 - rect1.origin.x=267.0f- rect.size.width;
 - }else {
 - rect.origin.x = 26.0f;
 - rect1.origin.x=267.0f;
 - }
 - [myButton setFrame:rect1];
 - [myView setFrame:rect];
 - [UIView commitAnimations];
 - }
 - @end
 
源代碼:http://easymorse-iphone.googlecode.com/svn/trunk/ipad.scrollView/
上述代碼雖然可以實(shí)現(xiàn)視圖的移動(dòng),但是有一個(gè)問(wèn)題沒(méi)有實(shí)現(xiàn),就是一個(gè)視圖如果在屏幕中間,不能實(shí)現(xiàn)點(diǎn)擊一個(gè)按鈕,從無(wú)到有而且是從一側(cè)移到另一側(cè)的動(dòng)畫(huà)。
小結(jié):IOS開(kāi)發(fā)實(shí)例 View實(shí)現(xiàn)動(dòng)畫(huà)效果的內(nèi)容介紹完了,希望本文對(duì)你有所幫助。















 
 
 


 
 
 
 