黑马程序员技术交流社区

标题: iOS基础交流 [打印本页]

作者: 李艳兵    时间: 2015-11-19 22:29
标题: iOS基础交流

#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

作者: 李凯666    时间: 2015-11-19 22:46
没有注释的吗?
作者: chenxinju    时间: 2015-11-19 23:38
这是OC 吗 还是有点看不懂 ,看来学习的路还很远啊  




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2