难点:
1.创建2个UIButton的时间
a按钮:移动View
b按钮:回复位置
2.保证View的移动
复习次数:5次
5月13日
5月16日
5月26日
5月30日
5月31日
源码:
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *myBtn1=[UIButton buttonWithType:UIButtonTypeRoundedRect];
myBtn1.frame=CGRectMake(50, 500, 80, 40);
[myBtn1 setTitle:@"按下移动" forState:UIControlStateNormal];
[myBtn1 addTarget:self action:@selector(pressMove) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:myBtn1];
UIButton *myBtn2=[UIButton buttonWithType:UIButtonTypeRoundedRect];
myBtn2.frame=CGRectMake(50, 150, 80, 40);
[myBtn2 setTitle:@"按下移动" forState:UIControlStateNormal];
[myBtn2 addTarget:self action:@selector(pressRect) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:myBtn2];
UIView *vc=[[UIView alloc] initWithFrame:CGRectMake(1, 250, 100, 100)];
vc.backgroundColor=[UIColor yellowColor];
vc.tag=101;
[self.view addSubview:vc];
}
-(void)pressMove
{
UIView *vc=[[UIView alloc]init];
vc=[self.view viewWithTag:101];
vc.backgroundColor=[UIColor darkGrayColor];
vc.frame=CGRectMake(vc.frame.origin.x+10, vc.frame.origin.y+50, 200, 200);
[self.view addSubview:vc];
}
-(void)pressRect
{
UIView *vc=[[UIView alloc]init];
vc=[self.view viewWithTag:101];
vc.frame=CGRectMake(1, 250, 100, 100);
}