创建viewController的视图UI
手动创建
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
UIViewController * viewController = [[UIViewController alloc] init];
self.window.rootViewController = viewController;
xib文件创建
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
UIViewController * viewController = [[UIViewController alloc] init];
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];
NSBundle * bundle = [NSBundle mainBundle];
NSArray * array = [bundle loadNibNamed:@"view" owner:self options:nil];
UIView *myView = [array lastObject];
viewController.view = myView;
属性
view.backgroundColor = [UIColor yellowColor];
view.alpha = 1;
self.window.alpha = 1;
view.hidden = NO;
view.center = self.window.center;
view.tag = 100;
方法
多个视图之间位置的移动
[self.window bringSubviewToFront:view];
[self.window sendSubviewToBack:view];
[self.window exchangeSubviewAtIndex:0 withSubviewAtIndex:4];
视图变换
在原本视图上变换
view.transform = CGAffineTransformMakeScale(0.5, 0.5);
view.transform = CGAffineTransformMakeScale(2, 2);
view.transform = CGAffineTransformMakeRotation(M_PI_4);
view.transform = CGAffineTransformMakeTranslation(100, 100);
在上一次变换的基础上再次变换
view.transform = CGAffineTransformRotate(view.transform, M_PI_4);
view.transform = CGAffineTransformTranslate(view.transform, 50, 50);
view.transform = CGAffineTransformScale(view.transform, 1, 1);
view.transform = CGAffineTransformIdentity;
动画
常规动画
[UIView beginAnimations:@"平移动画" context:nil];
[UIView setAnimationDuration:2];
[UIView setAnimationDelay:1];
view.transform = CGAffineTransformRotate(_view.transform, M_PI_4);
[UIView commitAnimations];
[UIView setAnimationDelegate:self];
[UIView setAnimationWillStartSelector:@selector(selector)];
-animationWillStart:(NSString *)animationID context:(void *)context
[UIView setAnimationDidStopSelector:@selector(selector)];
-animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
Block动画
[UIView animateWithDuration:0.5
animations:^{
_view.transform = CGAffineTransformRotate(_view.transform, M_PI);
} completion:^(BOOL finished) {
}];