UI基础2

UIView常见属性和方法

UIView(UIViewGeometry):几何

frame:边框,CGSize,CGPoint,自身左上角相对父容器的位置
bounds:边界,x和y默认为0,修改后不会影响自身位置,通过它可以修改控件的大小
center:视图的中心点,通过它可以修改控件的位置
transform:通过它可以修改位置,也可以修改大小,还可以做旋转

UIView(UIViewHierarchy):层次

superview:父控件
subviews:所有子控件
addSubview:添加一个子控件
removeFromSuperview:从父控件中移除自己

UIView(UIViewRendering):渲染

backgroundColor:背景颜色
alpha:透明度
UIView(UIViewAnimation):动画
UIView(UIViewAnimationWithBlocks):block动画

transform

const CGAffineTransform CGAffineTransformIdentity:复原
CGAffineTransform CGAffineTransformMakeTranslation(CGFloat tx,
CGFloat ty) 在初始状态下移动
CGAffineTransform CGAffineTransformMakeScale(CGFloat sx, CGFloat sy)在初始状态下缩放
CGAffineTransform CGAffineTransformMakeRotation(CGFloat angle)在初始状态下旋转
CGAffineTransform CGAffineTransformTranslate(CGAffineTransform t,
CGFloat tx, CGFloat ty) 在形变的状态下移动
CGAffineTransform CGAffineTransformScale(CGAffineTransform t,
CGFloat sx, CGFloat sy) 在形变的状态下缩放
CGAffineTransform CGAffineTransformRotate(CGAffineTransform t,
CGFloat angle) 在形变的状态下旋转
通过frame修改大小,左上角保持不变
通过bounds修改大小,中心点保持不变

block动画
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay usingSpringWithDamping:(CGFloat)dampingRatio initialSpringVelocity:(CGFloat)velocity options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL finished))completion

duration:持续时间
delay:延迟时间
dampingRatio:弹跳系数
velocity:动画完成速度
options:选项
(void (^)(void))animations:要执行动画的代码块
(void (^ __nullable)(BOOL finished))completion:动画完成执行的代码块

帧动画
@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIImageView *imgView;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
}
-(void)setupUI{
    NSMutableArray *arrM = [NSMutableArray array];
    int count = 25;
    for (int i = 1 ; i <= count; i++) {
        NSString *name =[NSString stringWithFormat:@"father%03d",i];
        UIImage *img = [UIImage imageNamed:name];
        [arrM addObject:img];
    }
    self.imgView.image = [UIImage animatedImageWithImages:arrM duration:count * 0.08];
}

@end
咻一咻
UI基础2_第1张图片

v.layer.cornerRadius 设置视图的圆角

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
}
-(void)setupUI{
    //设置背景颜色
    self.view.backgroundColor = [UIColor colorWithRed:26/255.0 green:28/255.0 blue:49/255.0 alpha:1.0];
    //添加支付宝按钮
    UIButton *btn = [[UIButton alloc] init];
    [btn setImage:[UIImage imageNamed:@"alipay_msp_op_success"] forState:UIControlStateNormal];
    [btn sizeToFit];
    btn.center = self.view.center;
    [self.view addSubview:btn];
    //设置背景circle
    UIView *v = [self createCircle];
    [self.view insertSubview:v belowSubview:btn];
    //添加点击事件
    [btn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    
}
//点击触发
-(void)click:(UIButton *)sender{
    //禁用交互
    sender.enabled = NO;
    //生成效果
    for (int i = 0; i < 20; i++) {
    UIView *v = [self createCircle];
    [self.view insertSubview:v belowSubview:sender];
    //缩放倍数
    CGFloat scale = 8.0;
    [UIView animateWithDuration:1.8
                          delay:0.5 *i
                        options:0
                     animations:^{
                         v.backgroundColor = self.view.backgroundColor;
                         v.transform = CGAffineTransformMakeScale(scale, scale);
                     } completion:^(BOOL finished) {
                         [v removeFromSuperview];
                     }];
    }
}
//生成view
-(UIView *)createCircle{
    UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    v.center = self.view.center;
    v.layer.cornerRadius = 50;
    v.backgroundColor = [UIColor colorWithRed:47/255.0 green:167/255.0 blue:244/255.0 alpha:1.0] ;
    return v;
}

@end

你可能感兴趣的:(UI基础2)