UIView 实战习题

UIView 实战习题

 一 按钮操作

1 题目描述

 

2 代码

//
//  WHBLAPViewController.m
//  03-按钮操作
//
//  Created by whblap on 14-5-26.
//  Copyright (c) 2014年 whblap. All rights reserved.
//

#import "WHBLAPViewController.h"
// 设置位移像素点
#define displacement 10
// 设置旋转角度大小
// C++里面预编译处理 是这样写的  const int displacement  = 10;
@interface WHBLAPViewController ()

@end

@implementation WHBLAPViewController

#pragma mark - 控制按钮上下左右走动 
- (IBAction)butten:(id)sender {
    // OC语法规定:不允许直接修改 某个对象中结构体属性的成员
    
    // 设置动画开始
    [UIView beginAnimations:nil context:nil];
    // 设置动画时间
    [UIView setAnimationDuration:0.5];
    CGRect tempFrame = _btn.frame; // 将_btn位置属性赋值给临时的tempFrame
    
    int tag = [sender tag];
//    CGFloat displacement = 10;
    switch (tag) {
        case 1:
            tempFrame.origin.y -= displacement;
            break;
        case 2:
            tempFrame.origin.y += displacement;
            break;
        case 3:
            tempFrame.origin.x -= displacement;
            break;
        case 4:
            tempFrame.origin.x += displacement;
            break;
    }
    _btn.frame = tempFrame;
    // 结束动画
    [UIView commitAnimations];

}
- (IBAction)rotateAndZoom:(id)sender {
    switch ([sender tag]) {
        case 5:
            _btn.transform = CGAffineTransformRotate(_btn.transform, -M_PI_4); //在原来比例——btn.transform下再放大
            break;
        case 6:
            _btn.transform = CGAffineTransformRotate(_btn.transform, +M_PI_4);
            break;
        case 7:
            _btn.transform = CGAffineTransformScale(_btn.transform, 1.2, 1.2);
            break;
        case 8:
            _btn.transform = CGAffineTransformScale(_btn.transform, 0.8, 0.8);
            break;
    }
}
@end

 

 


 

 

posted @ 2014-07-06 10:17  ゴルツの爱萍纳閣下  阅读(162)  评论(0编辑  收藏  举报