// // ViewController.m // 02--anniu按钮-勾了git // // Created by LongMa on 15/8/29. // Copyright (c) movedDistance15年 itcast. All rights reserved. // #import "ViewController.h" #define movedDistance 20 typedef enum { topButton = 10, bottomButton, leftButton, rightButton, zoomOut, zoomIn }kButton; @interface ViewController () @property IBOutlet UIButton* buttonOfImage; - (IBAction)move:(UIButton *)button; @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)zoom:(UIButton*) button { CGRect bounds = self.buttonOfImage.bounds; if (button.tag == zoomOut) { bounds.size.height += movedDistance; bounds.size.width += movedDistance; }else { bounds.size.height -= movedDistance; bounds.size.width -= movedDistance; } self.buttonOfImage.bounds = bounds; /* CGRect orgframe = self.buttonOfImage.frame; if (button.tag == zoomOut) { orgframe.size.height += movedDistance; orgframe.size.width += movedDistance; }else { orgframe.size.height -= movedDistance; orgframe.size.width -= movedDistance; } self.buttonOfImage.frame = orgframe; */ } - (IBAction)move:(UIButton *)button { //1.获取中心 CGPoint center = self.buttonOfImage.center; //2.判断按钮并修改坐标 switch (button.tag) { case topButton: center.y -= movedDistance; break; case bottomButton: center.y += movedDistance; break; case leftButton: center.x -= movedDistance; break; case rightButton: center.x += movedDistance; break; default: break; } //3.重新赋值 self.buttonOfImage.center = center; /* CGRect frameOfImg = self.buttonOfImage.frame;//无 * switch (button.tag) { case topButton: frameOfImg.origin.y -= movedDistance; break; case bottomButton: frameOfImg.origin.y += movedDistance; break; case leftButton: frameOfImg.origin.x -= movedDistance; break; case rightButton: frameOfImg.origin.x += movedDistance; break; default: break; } self.buttonOfImage.frame = frameOfImg; */ } @end
时间: 2024-10-25 06:52:06