IOS学习 UIView 页面布局
2016-02-16 15:58
441 查看
#import "ViewController.h"
@interface
ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super
viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIView *view1 = [[UIView
alloc]initWithFrame:CGRectMake(100,
100, 200,
100)];
view1.tag = 1;
//标示一个视图对象
// view1 = [self.view viewWithTag:1]; //可以通过tag查找view
view1.backgroundColor = [UIColor
redColor];
view1.clipsToBounds =
YES; //剪切掉视图外的内容
[self.view
addSubview:view1];
[view1 release];
UIView *view2 = [[UIView
alloc]initWithFrame:CGRectMake(0,
0, 100,
200)];
view2.tag = 2;
view2.backgroundColor = [UIColor
yellowColor];
[view1 addSubview:view2];
view2.alpha =
0.5; //透明度
[view2 release];
UIView *view3 = [[UIView
alloc]initWithFrame:CGRectMake(0,
0, 50,
50)];
view3.tag = 2;
view3.backgroundColor = [UIColor
greenColor];
[view1 addSubview:view3];
[view3 release];
UIButton *button = [UIButton
buttonWithType:UIButtonTypeRoundedRect];
button.frame =
CGRectMake(90,400,
140, 40);
[button setTitle:@"change"
forState:UIControlStateNormal];
[button addTarget:self
action:@selector(changeView)
forControlEvents:UIControlEventTouchUpInside];
[self.view
addSubview:button];
UILabel *label = [[UILabel
alloc]initWithFrame:CGRectMake(5,
0, 50,
30)];
label.text = @"jianguo";
label.textColor = [UIColor
whiteColor];
label.font = [UIFont
fontWithName:nil
size:14];
[view3 addSubview:label];
}
-(void)changeView{
NSLog(@"print");
UIView *vv = [self.view
viewWithTag:2];
[self.view
addSubview:vv];
NSLog(@"%@",vv);
[UIView
beginAnimations:nil
context:NULL];
//需要设置代理时
[UIView
setAnimationDuration:5];
//设置动画的持续时间
[UIView
setAnimationDelay:1];
//设置动画的延迟时间
vv.alpha = 0.0;
//淡出
// vv.backgroundColor = [UIColor blueColor];
vv.alpha = 1.0;
[UIView
commitAnimations]; //动画结束
// [UIView beginAnimations:nil context:NULL];
// [UIView setAnimationDuration:10];
// [UIView setAnimationDelay:5];
// vv.alpha = 1.0;
// [UIView setAnimationCurve:UIViewAnimationCurveLinear]; //动画的速率
// vv.center = CGPointMake(300, 500); //移动的位置
// [UIView commitAnimations];
}
- (void)didReceiveMemoryWarning {
[super
didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
@interface
ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super
viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIView *view1 = [[UIView
alloc]initWithFrame:CGRectMake(100,
100, 200,
100)];
view1.tag = 1;
//标示一个视图对象
// view1 = [self.view viewWithTag:1]; //可以通过tag查找view
view1.backgroundColor = [UIColor
redColor];
view1.clipsToBounds =
YES; //剪切掉视图外的内容
[self.view
addSubview:view1];
[view1 release];
UIView *view2 = [[UIView
alloc]initWithFrame:CGRectMake(0,
0, 100,
200)];
view2.tag = 2;
view2.backgroundColor = [UIColor
yellowColor];
[view1 addSubview:view2];
view2.alpha =
0.5; //透明度
[view2 release];
UIView *view3 = [[UIView
alloc]initWithFrame:CGRectMake(0,
0, 50,
50)];
view3.tag = 2;
view3.backgroundColor = [UIColor
greenColor];
[view1 addSubview:view3];
[view3 release];
UIButton *button = [UIButton
buttonWithType:UIButtonTypeRoundedRect];
button.frame =
CGRectMake(90,400,
140, 40);
[button setTitle:@"change"
forState:UIControlStateNormal];
[button addTarget:self
action:@selector(changeView)
forControlEvents:UIControlEventTouchUpInside];
[self.view
addSubview:button];
UILabel *label = [[UILabel
alloc]initWithFrame:CGRectMake(5,
0, 50,
30)];
label.text = @"jianguo";
label.textColor = [UIColor
whiteColor];
label.font = [UIFont
fontWithName:nil
size:14];
[view3 addSubview:label];
}
-(void)changeView{
NSLog(@"print");
UIView *vv = [self.view
viewWithTag:2];
[self.view
addSubview:vv];
NSLog(@"%@",vv);
[UIView
beginAnimations:nil
context:NULL];
//需要设置代理时
[UIView
setAnimationDuration:5];
//设置动画的持续时间
[UIView
setAnimationDelay:1];
//设置动画的延迟时间
vv.alpha = 0.0;
//淡出
// vv.backgroundColor = [UIColor blueColor];
vv.alpha = 1.0;
[UIView
commitAnimations]; //动画结束
// [UIView beginAnimations:nil context:NULL];
// [UIView setAnimationDuration:10];
// [UIView setAnimationDelay:5];
// vv.alpha = 1.0;
// [UIView setAnimationCurve:UIViewAnimationCurveLinear]; //动画的速率
// vv.center = CGPointMake(300, 500); //移动的位置
// [UIView commitAnimations];
}
- (void)didReceiveMemoryWarning {
[super
didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
相关文章推荐
- SOUI GDI+渲染引擎下的字体特效
- iOS对UIView对象或子类对象截屏(截取的内容以UIImage的形式存储)
- UICollectionView基础
- 降低对象的引用级别到软引用 class SoftValueMap<K, V> extends HashMap<K, V>
- nyoj--1100--WAJUEJI which home strong!(bfs)
- nyoj--1100--WAJUEJI which home strong!(bfs)
- android 开源组件合集-UI篇(2014-08-25更新)
- MySQL关于Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp
- UITextView控件的用法
- easyUI datagird实现对行的任意拖拽移动位置
- MySQL的错误:No query specified
- 各种UIGestureRecognizer 手势
- UIWindow
- Android-节日短信送祝福(UI篇:3-选择短信与发送短信的Activity的实现)
- 二手吧软件学习build.xml
- VS批生成(Batch Build)不可使用的问题
- LeetCode "Increasing Triplet Subsequence" !!
- UIScrollView,UIView转换UIImage代码(整个view截图, 不只是可视区域)
- hdoj4908BestCoder Sequence
- NSURLRequestCachePolicy—iOS缓存策略