码迷,mamicode.com
首页 > 其他好文 > 详细

UI基础_transform

时间:2015-08-26 20:01:15      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:

  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

 

UI基础_transform

标签:

原文地址:http://www.cnblogs.com/xjf125/p/4761395.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!