iOS 核心動畫-錨點

錨點是CALayer 的一個屬性


anchorPoint  錨點  以錨點爲中心  執行動畫(可以理解爲    漁夫  固定船的點)

anchorPoint  默認的是(0.5,0.5) 在中間  錨點是一個比例

 anchorPoint 在左上角的時候 00

 

 anchorPoint 在右上角的時候 10

 

 anchorPoint 在左下角的時候 01

 

 anchorPoint 在右下角的時候 11


有關錨點使用(例子):

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

{

    UITouch *touch = [touches anyObject];

    CGPoint touchPoint = [touch locationInView:self.view];

    

    

//    通過 點擊屏幕的x/屏幕的寬度    得到點擊的點與屏幕的一個比例

    CGFloat x = (touchPoint.x)/CGRectGetWidth([UIScreen mainScreen].bounds);

//    通過 點擊屏幕的y/屏幕的高度    得到點擊的點與屏幕的一個比例

    CGFloat y = (touchPoint.y)/CGRectGetHeight([UIScreen mainScreen].bounds);

//    改變 ship 錨點

    ship.anchorPoint =CGPointMake(x, y);

    

     NSLog(@"錨點X:%f 錨點Y:%f",ship.anchorPoint.x,ship.anchorPoint.y);  //打印錨點的位置

    

    

    CGFloat cx = CGRectGetWidth(ship.bounds)*ship.anchorPoint.x;

    CGFloat cy = CGRectGetWidth(ship.bounds)*ship.anchorPoint.y;

    APLayer.position =CGPointMake(cx, cy);

    

    

//   角度值經計算轉化爲弧度值。要把角度值轉化爲弧度值,可以使用一個簡單的公式Mπ/180

//    <#CGFloat tx#>, <#CGFloat ty#>, <#CGFloat tz#>  3個軸  0  1  把誰設置爲1 就圍繞它旋轉

    ship.transform = CATransform3DMakeRotation(45*M_PI/18, 0, 0, 1);

    

}

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

{

    ship.transform = CATransform3DIdentity;


}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章