UI基础_transform

  1. #import "ViewController.h"
  2. typedef enum
  3. {
  4.     ButtonTypeLeft = 1,
  5.     ButtonTypeRight,
  6.     ButtonTypeUp,
  7.     ButtonTypeDown,
  8.     ButtonTypeRotleL,
  9.     ButtonTypeRotleR,
  10.     ButtonTypeScaleUp,
  11.     ButtonTypeScaleDown
  12. }ButtonType;
  13. @interface ViewController ()
  14. @property (strong, nonatomic) IBOutlet UIView *viewMan;
  15.  @end
  1. @implementation ViewController
  2. - (IBAction)buttonDirectionClicked:(UIButton *)sender
  3. {
  4.     //获取屏幕的宽度、高度
  5.     NSInteger screenWidth = self.view.frame.size.width;
  6.     NSInteger screenHeight = self.view.frame.size.height;
  7.     //获取viewMain的位置信息
  8.     CGRect rect = self.viewMan.frame;
  9.     //设置移动的尺寸
  10.     NSInteger offSet = 10;
  11.     switch (sender.tag) {
  12.         case ButtonTypeLeft:
  13.             rect.origin.x -= offSet;
  14.             if (rect.origin.x <= -rect.size.width ) {
  15.                 rect.origin.x = screenWidth;
  16.             }
  17.             break;
  18.         case ButtonTypeRight:
  19.             rect.origin.x += offSet;
  20.             if (rect.origin.x >= screenWidth) {
  21.                 rect.origin.x = -rect.size.width;
  22.             }
  23.             break;
  24.         case ButtonTypeUp:
  25.             rect.origin.y -= offSet;
  26.             if (rect.origin.y <= -rect.size.height) {
  27.                 rect.origin.y = screenHeight;
  28.             }
  29.             break;
  30.         case ButtonTypeDown:
  31.             rect.origin.y += offSet;
  32.             if (rect.origin.y >= screenHeight) {
  33.                 rect.origin.y = -rect.size.height;
  34.             }
  35.             break;
  36.     }
  37.     self.viewMan.frame = rect;
  38. }
  39. - (IBAction)buttonRotale:(UIButton *)sender
  40. {
  41.     CGAffineTransform form = self.viewMan.transform;
  42.     switch (sender.tag) {
  43.         case ButtonTypeRotleL:
  44.             form = CGAffineTransformRotate(form, -M_2_PI/2);
  45.             break;
  46.         case ButtonTypeRotleR:
  47.             form = CGAffineTransformRotate(form, M_2_PI/2);
  48.         default:
  49.             break;
  50.     }
  51.     self.viewMan.transform = form;
  52. }
  53. - (IBAction)buttonScale:(UIButton *)sender
  54. {
  55.     CGAffineTransform form = self.viewMan.transform;
  56.     CGFloat scaleFator = 0.0f;
  57.     switch (sender.tag) {
  58.         case ButtonTypeScaleUp:
  59.             scaleFator = 1.5;
  60.             break;
  61.          case ButtonTypeScaleDown:
  62.             scaleFator = 0.5;
  63.     }
  64.     form = CGAffineTransformScale(form, scaleFator, scaleFator);
  65.     self.viewMan.transform = form;
  66. }
  67. - (void)viewDidLoad {
  68.     [super viewDidLoad];
  69.     // Do any additional setup after loading the view, typically from a nib.
  70. }
  71. - (void)didReceiveMemoryWarning {
  72.     [super didReceiveMemoryWarning];
  73.     // Dispose of any resources that can be recreated.
  74. }
  75. @end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值