CGPoint Point = CGPointMake(x,y);//設置 CGSize size = CGSizeMake(width,height);//大小 CGRect rect = CGRectMake(x,y,width,height);//位置和大小
```Objective-c
//經過xib方式來建立視圖對象
NSBundle *bundle = [NSBundle mainBundle];
NSArray *arr = [bundle loadNibNamed:@"myView" owner:self
options:nil];
UIView *myView = [arr objectAtIndex:0];數組
```Objective-c //代碼建立視圖對象 CGRect viewRect = CGRectMake(0,0,100,100); UIView *myView =[[UIView alloc] initWithFrame:viewRect];
##查找視圖 - UIView類中有一個tag屬性,經過這個屬性能夠標誌一個視圖對象(整數) - 獲取的方法,viewWithTag:方法來檢索標誌過的子視圖 ```Objective-c UIView *myView = [[UIView alloc] initWithFrame:CGRectmake(0,0,100,100)]; myView.tag = 100; // 經過tag查找view UIView *myView = [self.view vieWithTag:100];
CGAffineTransform transform = rootView.transform; rootView.transform = CGAffineTransformScale(transform,0.5,0.5); rootView.transform = CGAffineTransformRotae(transform,0.33); CGAffineTransformScale(transform,0.5,0.5); rootView.transform = CGAffineTransformTranslate(transform,100,100);
UIImageView *imgeView1 = [[UIImageView alloc] initWithFrame:CFRectMake(320/2-200/2,30,200,200)]; imgeView1.imge = [UIImage imageNamed:@"01"]; imgeView1.backgroundColor = [UIColor redColor]; imgeView1.contentMode = UIViewContentModeScaleAspectFit; [self.window addSubview:imgeView1]; [imView1 release]; UIImageView *imgeView2 = [[UIImageView alloc] initWithFrame:CFRectMake(320/2-200/2,240,200,200)]; imgeView2.backgroundColor = [UIColor yelloColor]; imgeView2.contentMode = UIViewContentModeBottom; [self.window addSubview:imgeView2]; [imView2 release];
經過UIView調用setAnmationDelegate:方法來設置委託,並經過setAnimationWillStartSelector:和setAnimationDidStopSelector:方法來指定接受消息的選擇器方法。消息處理方法形式以下:(void)animationWillStart:(NSString *)animationID context:(void *)context;
(void)animationDidStop:(NSString *)animationID finished context:(void *)context;
上面的兩個方法的animationID和context參數和動畫塊開始時傳給beginAnimations:context:
方法的參數相同
+ animationID - 應用程序提供的字符串,用於標識一個動畫塊中的動畫
+ context - 應用程序提供的對象,用於向委託對象傳遞額外的信息函數
setAnimationDidStopSelector:選擇器方法還有一個參數——即一個布爾值。若是動畫順利完成,沒有被其餘動畫取消或中止,則該值爲YES。動畫
setAnimationStartDateS
方法來設置動畫在commitAnimations:
方法返回以後的發生日期。setAnimationDelay:
方法來設置實際發生動畫和commitAnimations:
方法返回的時間點之間的間隔setAnimationDuration:
方法來設置動畫的持續秒數setAnimationCurve:
方法來設置動畫過程的相對速度,好比動畫可能在啓動階段逐漸加速、而在結束階段逐漸減小,或者這個過程都保持相同的速度setAnimationRepeatCount:
方法來設置動畫的重複次數setAnimationRepeatAutoreverses:
方法來指定動畫在到達目標值時是否自動反向播放。但是結合使用這個方法和setAnimationRepeatCount:
方法,使各個屬性在初始值和目標值之間平滑切換一段時間。setAnimationsEnableed:
方法來暫時禁止動畫,在完成修改後才從新激活動畫,在調用setAnimationsEnabled:
方法並傳入NO值以後,全部的改變都不會產生動畫效果,指定用YES值再次調用這個方法或者提交這個動畫塊是,動畫纔會恢復,能夠用areAnimationsEnable:
方法來肯定當前是否激活動畫。-(void)animationAlpha { [UIView beginAnimations:nil context:NULL];// 須要設置代理時 [UIView setAnimationDuration:1];// 動畫的持續時間 [UIview setAnimationDelay:1];// 動畫延遲時間 view2.apleha = 0.0; [UIView commitAnimations];// 標記着動畫塊的結束 } -(void)animationFrame { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:5]; [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];// 動畫相對速度,開始和結束的時候慢,中間快 view.center = CGPointMake(0,0); [UIView commitAnimations]; }