IOS基础学习笔记一:UIView学习

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;

        }

     ];















































發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章