- #import "ViewController.h"
- typedef enum
- {
- ButtonTypeLeft = 1,
- ButtonTypeRight,
- ButtonTypeUp,
- ButtonTypeDown,
- ButtonTypeRotleL,
- ButtonTypeRotleR,
- ButtonTypeScaleUp,
- ButtonTypeScaleDown
- }ButtonType;
- @interface ViewController ()
- @property (strong, nonatomic) IBOutlet UIView *viewMan;
- @end
- @implementation ViewController
- - (IBAction)buttonDirectionClicked:(UIButton *)sender
- {
- //获取屏幕的宽度、高度
- NSInteger screenWidth = self.view.frame.size.width;
- NSInteger screenHeight = self.view.frame.size.height;
- //获取viewMain的位置信息
- CGRect rect = self.viewMan.frame;
- //设置移动的尺寸
- NSInteger offSet = 10;
- switch (sender.tag) {
- case ButtonTypeLeft:
- rect.origin.x -= offSet;
- if (rect.origin.x <= -rect.size.width ) {
- rect.origin.x = screenWidth;
- }
- break;
- case ButtonTypeRight:
- rect.origin.x += offSet;
- if (rect.origin.x >= screenWidth) {
- rect.origin.x = -rect.size.width;
- }
- break;
- case ButtonTypeUp:
- rect.origin.y -= offSet;
- if (rect.origin.y <= -rect.size.height) {
- rect.origin.y = screenHeight;
- }
- break;
- case ButtonTypeDown:
- rect.origin.y += offSet;
- if (rect.origin.y >= screenHeight) {
- rect.origin.y = -rect.size.height;
- }
- break;
- }
- self.viewMan.frame = rect;
- }
- - (IBAction)buttonRotale:(UIButton *)sender
- {
- CGAffineTransform form = self.viewMan.transform;
- switch (sender.tag) {
- case ButtonTypeRotleL:
- form = CGAffineTransformRotate(form, -M_2_PI/2);
- break;
- case ButtonTypeRotleR:
- form = CGAffineTransformRotate(form, M_2_PI/2);
- default:
- break;
- }
- self.viewMan.transform = form;
- }
- - (IBAction)buttonScale:(UIButton *)sender
- {
- CGAffineTransform form = self.viewMan.transform;
- CGFloat scaleFator = 0.0f;
- switch (sender.tag) {
- case ButtonTypeScaleUp:
- scaleFator = 1.5;
- break;
- case ButtonTypeScaleDown:
- scaleFator = 0.5;
- }
- form = CGAffineTransformScale(form, scaleFator, scaleFator);
- self.viewMan.transform = form;
- }
- - (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.
- }
- @end
时间: 2024-10-14 00:18:24