首页 > 其他 > 详细

核心动画2

时间:2015-10-16 06:23:13      阅读:281      评论:0      收藏:0      [点我收藏+]

//

//  ViewController.m

//  UI-NO-36-1 核心动画-2

//

//  Created by 容伟 on 15/9/15.

//  Copyright (c) 2015年 容伟. All rights reserved.

//

 

#import "ViewController.h"

 

@interface ViewController (){

    

    CALayer *myLayer;

    CGFloat width;

    CALayer *imageLayer;

}

 

@end

 

@implementation ViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];

    [self addLayer];

    [self addImageLayer];

 

 

}

 

- (void)addLayer {

    width = 100;

    

    myLayer = [[CALayer alloc] init];

    myLayer.backgroundColor = [UIColor whiteColor].CGColor;

    myLayer.shadowOpacity = 1.0;   //  阴影 默认的透明度是 0

    myLayer.shadowColor = [UIColor yellowColor].CGColor;

    myLayer.bounds = CGRectMake(0, 0, width, width);

    myLayer.position = self.view.center;

    myLayer.borderWidth = 2;

    myLayer.borderColor = [UIColor blackColor].CGColor;

    myLayer.cornerRadius = width/2;

    myLayer.shadowOffset = CGSizeMake(-1, -1);

//    myLayer.contents = (__bridge id)([UIImage imageNamed:@"12.jpg"].CGImage);

//    myLayer.masksToBounds = YES;

    

    

    [self.view.layer addSublayer:myLayer];

}

 

- (void)addImageLayer {

    imageLayer = [[CALayer alloc] init];

    imageLayer.bounds = CGRectMake(0, 0, width, width);

    imageLayer.position = self.view.center;

    imageLayer.cornerRadius = myLayer.cornerRadius;

    imageLayer.contents = (__bridge id)([UIImage imageNamed:@"12.jpg"].CGImage);

        imageLayer.masksToBounds = YES;

    imageLayer.borderWidth = 2;

    imageLayer.borderColor = [UIColor whiteColor].CGColor;

    [self.view.layer addSublayer:imageLayer];

}

 

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [touches anyObject];

    [self changeStateWith:[touch locationInView:self.view]];

}

 

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [touches anyObject];

    [self changeStateWith:[touch locationInView:self.view]];

}

 

- (void)changeStateWith:(CGPoint)position {

    myLayer.position = position;

    width = width == 100 ? 300:100;

    myLayer.bounds = CGRectMake(0, 0, width, width);

    myLayer.cornerRadius = width/2;

    

    imageLayer.position = position;

    imageLayer.bounds = CGRectMake(0, 0, width, width);

    imageLayer.cornerRadius = myLayer.cornerRadius;

}

 

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

@end

 

核心动画2

原文:http://www.cnblogs.com/wukun16/p/4884163.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!