#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
|
|