每个控件都是一个容器 因此一个控件能放到另外一个控件的内部ios
属性git
@property(nonatomic) CGRect frame; @property(nonatomic) CGRect bounds; @property(nonatomic) CGPoint center;
方法dom
- (void)removeFromSuperview; - (void)insertSubview:(UIView *)view atIndex:(NSInteger)index; - (void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2; - (void)addSubview:(UIView *)view; - (void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview; - (void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview; - (void)bringSubviewToFront:(UIView *)view; - (void)sendSubviewToBack:(UIView *)view;
示例:动画
//方法1:添加一个view UIView* view = [[UIView alloc] init]; //距离父视图左边距和上边距的距离,自己本身的宽和高 CGRect rect = CGRectMake(10, 30, 100, 100); //肯定当前视图的位置与大小 view.frame = rect; //改变背景颜色 view.backgroundColor = [UIColor redColor]; //能够把咱们的view添加到window上 [self.window addSubview:view]; [view release]; //方法2:再添加一个view UIView* view2 = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)]; view2.backgroundColor = [UIColor greenColor]; [view addSubview:view2]; [view2 release]; */ ////循环建立 5 个view 么么哒 for (int i = 0; i < 5; i++) { //随机颜色 int red = arc4random()%255; int green = arc4random()%255; int blue = arc4random()%255; //NSLog(@"%d %d %d ",red,green,blue); //设置颜色哟 UIColor* color = [UIColor colorWithRed:red/255.0 green:green/255.0 blue:blue/255.0 alpha:1.0]; //10,60,110,160,210 float x = 10 + 50 * i; //30,80,130,180,230 float y = 30 + 50 * i; UIView* view = [[UIView alloc] initWithFrame:CGRectMake(x, y, 100, 100)]; view.backgroundColor = color; [self.window addSubview:view]; ///[view release]; } //父视图上全部的子视图 //self.window.subviews //子视图拿到父视图指针 //view1.superview //移除视图 //[view1 removeFromSuperview]; //视图隐藏 //view1.hidden = YES; //透明度 //view2.alpha = 0.5; //放到哪一个视图之上 //[self.window insertSubview:view2 aboveSubview:view3]; //放到哪一个视图之下 //[self.window insertSubview:view3 belowSubview:view1]; //[self.window insertSubview:view1 atIndex:2]; //把子视图放到最上面 //[self.window bringSubviewToFront:view1]; //把子视图放到最下面 //[self.window sendSubviewToBack:view3]; //交换子视图的位置 //[self.window exchangeSubviewAtIndex:0 withSubviewAtIndex:2]; //让子视图自适应父视图的改变 bgView.autoresizesSubviews = YES; //设置子视图的适应方式 subView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin;
这里介绍一下 UIView的简单的动画效果 atom
//动画块 [UIView beginAnimations:nil context:nil]; //时间 [UIView setAnimationDuration:10.0]; //动画效果 [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:NO]; //减速效果 [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; [UIView setAnimationDelegate:self]; [UIView setAnimationWillStartSelector:@selector(animationWillStart)]; [UIView setAnimationDidStopSelector:@selector(animationWillStop)]; ////下面是本身要作的事情 这里交换一下两个UIView的位置 [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1]; [UIView commitAnimations];
- (void)animationWillStart{ NSLog(@"动画 开始"); } - (void)animationWillStop{ NSLog(@"动画结束"); }
渐变消失url
////////////////渐变消失 UIImageView *splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-100)]; splashView.image = [UIImage imageNamed:@"222"]; NSURL *url = [NSURL URLWithString:str]; [splashView setImageWithURL:url]; [self.window addSubview:splashView]; [self.window bringSubviewToFront:splashView]; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:3.0]; [UIView setAnimationTransition:UIViewAnimationTransitionNone forView: self.window cache:YES]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(startupAnimationDone)]; splashView.alpha = 0.0; splashView.frame = CGRectMake(-60, -85, 440, 635); [UIView commitAnimations];
旋转指针
CGAffineTransform myaffine3 = CGAffineTransformMakeRotation(3.1415026/4); view1.transform = myaffine3;//断点2
旋转渐变消失code
[UIView animateWithDuration:3.0 animations:^{ view1.frame = CGRectMake(self.view.bounds.size.width-50, 100, 50, 50); view1.alpha = 0; view1.transform = CGAffineTransformMakeRotation(3.1415926); } completion:^(BOOL finished) { NSLog(@"animation completion!"); }];
推荐orm
ios核心动画高级技巧rem