iOS Dev (28) 三种基本的 2D 放射变换

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

iOS Dev (28) 三种基本的 2D 放射变换

上一篇:Linux命令详解之find


下一篇:Storm Found multiple defaults.yaml resources