UIView屬性:
UIWindows *window
UIView *superView :父級View
NSArray *subviews :子View
CGRect frame :包含UIView 左上角的起始點 和 CGSize(長、寬)
CGpoint center
CGAffineTransForm transform :形變屬性 可用於 縮放(scale)、旋轉(rotate)、平移
1.在viewDidLoad方法中 添加按鈕
UIButton *btn = [[UIButton alloc] init];
btn.frame = CGRectMake(0,0,100,100);
btn.backgroundColor = [UIColor orangeColor];
[btn setTitle:@"一個按鈕" forState:UIControllStateNormal];
[btn setTitle:@"被人摸了" forState:UIControllStateHignlighted];
[self.view addSubview:btn];
圖片的尺寸,就是按鈕的尺寸
2.加載圖片---
//根據圖片名稱去項目文件系統中加載
UIImage *leftNormal = [UIImage imageNamed:@"sub_black_prev.png"];
3.控件綁定監聽器
[btn addTarget:self action:@selector(directionBtnClick) forControlEvents:UIControlEventTouchUpInside];
4.監聽器的實現
-(void) directionBtnClick:(UIButton *)btn
{
NSLog(@"----------%@",btn);
}
3.設置控件按鈕的唯一標識:
NSInteger tag;
btn.tag = tag;
———————————————————
宏定義
#define kLeftTag 1
父控件,可以根據tag,拿到子控件.
OC規定:
不允許直接,修改對象內部的,結構體的,成員值.
CGPoint center = orangeBtn.center;
center.y -= 50;
orangeBtn.center = center;
case:
如果在case裏定義變量,必須用{}括住.
--------------------------------
IOS中的動畫效果:
非常簡單,用以下的代碼,包住要動的代碼,即可
方法一:
1.[UIView beginAnimations:nil context:nil];
2.[UIView setAnimationDuration:.3];
3.[UIView commitAnimation];
方法二:
[UIView animateWithDuration:.3
animations:^{//存放需要動畫執行的代碼
CGRect frame=lastView.frame;
frame.origin.x=lastView.frame.size.width;
lastView.frame=frame;
}
completion:^(BOOL finished) {//動畫執行完畢
[lastView removeFromSuperview];
_removeItem.enabled=self.view.subviews.count>1;
}
];