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]; }