你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS Dev (28) 三種基本的 2D 放射變換

iOS Dev (28) 三種基本的 2D 放射變換

編輯:IOS開發綜合

iOS Dev (28) 三種基本的 2D 放射變換



  • 基礎

    我們要用到的是:

    CGAffineTransform
    

    的一些函數(是 C 形式的函數)。

    縮放 scale 的定義:

    CGAffineTransform CGAffineTransformScale (
       CGAffineTransform t,
       CGFloat sx,
       CGFloat sy
    );
    

    旋轉 roate 的定義:

    CGAffineTransform CGAffineTransformRotate (
       CGAffineTransform t,
       CGFloat angle
    );
    

    平移 translate 的定義:

    CGAffineTransform CGAffineTransformTranslate (
       CGAffineTransform t,
       CGFloat tx,
       CGFloat ty
    );
    

    示例

    建立一個 Empty Project,直接該丫的 application 方法。

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
        UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(60, 100, 200, 200)];
        view1.tag = 101;
        view1.backgroundColor = [UIColor redColor];
        [self.window addSubview:view1];
    
        UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
        view2.tag = 102;
        view2.backgroundColor = [UIColor yellowColor];
        [view1 addSubview:view2];
    
        UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(110, 400, 100, 44)];
        btn.backgroundColor = [UIColor cyanColor];
        [btn addTarget:self action:@selector(onClick) forControlEvents:UIControlEventTouchUpInside];
        [self.window addSubview:btn];
    
        self.window.backgroundColor = [UIColor whiteColor];
        [self.window makeKeyAndVisible];
        return YES;
    }
    
    - (void)onClick
    {
        UIView *view2 = [[self.window viewWithTag:101] viewWithTag:102];
        view2.transform = CGAffineTransformScale(view2.transform, 0.8, 0.8);
        view2.transform = CGAffineTransformRotate(view2.transform, 0.2);
        view2.transform = CGAffineTransformTranslate(view2.transform, 50, 50);
    }
    

    -

    轉載請注明來自:http://blog.csdn.net/prevention

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved