2013-04-19 35 views
6

Tôi đã đoạn mã sau đó quay một CALayer bởi -45degrees trên trục Y:My CALayer chuyển đổi nắm giữ sau khi hình ảnh động, nhưng quan điểm biến mất

#define D2R(x) (x * (M_PI/180.0)) 

- (void) swipe:(UISwipeGestureRecognizer *)recognizer 
{   
    CATransform3D transform = CATransform3DMakeRotation(D2R(-45), 0, 1.0, 0); 
    transform.m34 = -1.0/850; 

    CABasicAnimation *transformAnimation = [CABasicAnimation animationWithKeyPath: @"transform"]; 
    transformAnimation.fillMode = kCAFillModeForwards; 
    transformAnimation.removedOnCompletion = NO; 
    transformAnimation.toValue = [NSValue valueWithCATransform3D:transform]; 
    transformAnimation.duration = 0.5; 

    [self.layer addAnimation:transformAnimation forKey:@"transform"]; 
} 

Các tác phẩm hoạt hình, ngoại trừ nó kết thúc với không có quan điểm - bỏ qua cài đặt m34 của tôi nếu tôi hiểu chính xác mọi thứ.

Halfway qua:

enter image description here

Cuối cùng:

enter image description here

Tôi đang làm gì sai?

Trả lời

2

Hoạt ảnh chỉ ảnh hưởng đến giao diện của chế độ xem trong khi hoạt ảnh. Nó không được áp dụng cho chế độ xem sau khi hoạt ảnh kết thúc. Bạn cần tự làm điều này. Tôi đoán một cái gì đó như thế này ngay sau khi thêm hoạt ảnh sẽ hoạt động:

self.layer.transform = transform; 

Bạn có thể làm điều này ngay lập tức vì hoạt ảnh sẽ ẩn nó cho đến khi hoạt ảnh hoàn tất.

1

Hãy thử điều này:

- (void) swipe:(UISwipeGestureRecognizer *)recognizer 
{   

    CATransform3D transform = CATransform3DIdentity; 
    transform.m34 = -10/850.0; 
    transform = CATransform3DRotate(transform, D2R(-45), 0, 1.0, 0); 

    CABasicAnimation *transformAnimation = [CABasicAnimation animationWithKeyPath: @"transform"]; 
    transformAnimation.fillMode = kCAFillModeForwards; 
    transformAnimation.removedOnCompletion = NO; 
    transformAnimation.toValue = [NSValue valueWithCATransform3D:transform]; 
    transformAnimation.duration = 0.5; 

    [self.layer addAnimation:transformAnimation forKey:@"transform"]; 
} 

Và chấm dứt hiệu lực là như thế này:

enter image description here