A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 李艳兵 中级黑马   /  2015-11-19 22:29  /  631 人查看  /  2 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文


#import "ViewController.h"

typedef enum {
    KTagUp = 1,
    KTagLeft,
    KTagDwon,
    KTagRight,
    KTagMinify,
    KTagplus
   
}KTag;

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIButton *upButton;

@property (weak, nonatomic) IBOutlet UIButton *leftButton;

@property (weak, nonatomic) IBOutlet UIButton *downButton;


@property (weak, nonatomic) IBOutlet UIButton *rightButton;

@property (weak, nonatomic) IBOutlet UIButton *minifyButton;

@property (weak, nonatomic) IBOutlet UIButton *plusButton;


@property (weak, nonatomic) IBOutlet UIButton *imageButton;

@end

@implementation ViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)clickMoveButtons:(UIButton *)sender{
    CGRect rect = self.imageButton.frame;
    switch (sender.tag) {
        case KTagUp:
            rect.origin.y -= 10;
            break;
        case KTagLeft:
            rect.origin.x -= 10;
            break;
        case KTagDwon:
            rect.origin.y += 10;
            break;
        case KTagRight:
            rect.origin.x += 10;
            break;
        default:
            break;
    }
   
    self.imageButton.frame = rect;
    [self changeButtonsState];
}
- (IBAction)clickScaleButtons:(UIButton *)sender {
   
    CGRect rect = self.imageButton.bounds;
    switch (sender.tag) {
        case KTagMinify:
            rect.size.width -= 10;
            rect.size.height -= 10;
            break;
        case KTagplus:
            rect.size.width += 10;
            rect.size.height += 10;
        default:
            break;
    }
   
    self.imageButton.bounds = rect;
    [self changeButtonsState];
}

- (void)changeButtonsState{
    CGFloat topMarginOfImageButton = self.imageButton.frame.origin.y;
    CGFloat leftMarginOfImageButton = self.imageButton.frame.origin.x;
    CGFloat downMarginOfImageButton = self.view.frame.size.height - topMarginOfImageButton - self.imageButton.frame.size.height;
    CGFloat rightMarginOfImageButton = self.view.frame.size.width - leftMarginOfImageButton - self.imageButton.frame.size.width;
   
    self.upButton.enabled = ((topMarginOfImageButton - 10) >= 0);
    self.leftButton.enabled =
    ((leftMarginOfImageButton - 10) >= 0);
    self.downButton.enabled = ((downMarginOfImageButton - 10) >= 0);
    self.rightButton.enabled =((rightMarginOfImageButton - 10) >= 0);
    self.plusButton.enabled = self.upButton.enabled && self.leftButton.enabled && self.downButton.enabled && self.rightButton.enabled;
   
    self.minifyButton.enabled = ((self.imageButton.frame.size.width - 10) >= 50);
}


@end

2 个回复

倒序浏览
李凯666 来自手机 中级黑马 2015-11-19 22:46:00
沙发
没有注释的吗?
回复 使用道具 举报
这是OC 吗 还是有点看不懂 ,看来学习的路还很远啊  
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马