2012-03-30 41 views
31

Tôi muốn có một hình ảnh trong ứng dụng iphone "pop-in" trên màn hình thay vì chỉ xuất hiện. Bởi "pop-in" tôi có nghĩa là nó sẽ phát triển từ một chấm nhỏ đến kích thước thực tế của nó. Để tham khảo, điều này hoàn toàn giống với hiệu ứng hoạt hình "pop" trong Keynote. Tôi hoàn toàn mới đối với hoạt ảnh iOS, vì vậy nếu ai đó có thể chỉ cho tôi theo hướng về hiệu ứng hoạt hình tôi sẽ cần sử dụng, nó sẽ được đánh giá cao.iOS - Hiệu ứng hoạt ảnh - Hình ảnh pop-in

Cảm ơn

Brian

CẬP NHẬT Tôi đã thêm mã này từ những gợi ý dưới đây. Điều này làm việc nhưng nó giảm kích thước hình ảnh của tôi xuống, thay vì lên. Tôi biết đó là bởi vì tôi có 0,01 là kích thước quy mô chuyển đổi, nhưng tôi muốn biết làm thế nào tôi có thể bắt đầu với một hình ảnh có kích thước 0.0 và mở rộng lên đến 1. Có phải chỉ là vấn đề đặt kích thước hình ảnh của tôi thành 0? Cảm ơn

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration: 0.2]; 
image.transform = CGAffineTransformMakeScale(0.01, 0.01); 
[UIView setAnimationDelegate:self]; 
[UIView commitAnimations]; 

Trả lời

78

Hiệu quả bạn đang muốn tìm một cái gì đó như thế này:

// instantaneously make the image view small (scaled to 1% of its actual size) 
view.transform = CGAffineTransformMakeScale(0.01, 0.01); 
[UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ 
    // animate it to the identity transform (100% scale) 
    view.transform = CGAffineTransformIdentity; 
} completion:^(BOOL finished){ 
    // if you want to do something once the animation finishes, put it here 
}]; 
+1

Có cách nào để phóng to hình ảnh từ một điểm khác với trung tâm không? – tiguero

+5

Đúng - thay đổi [điểm neo] của lớp (http://developer.apple.com/library/ios/#documentation/GraphicsImaging/Reference/CALayer_class/Introduction/Introduction.html#//apple_ref/doc/c_ref/CALayer) . 'theView.layer.anchorPoint = CGPointMake (0, 0) 'sẽ làm cho tỷ lệ khung nhìn từ phía trên bên trái của nó; '(1, 1)' là phần dưới bên phải của nó. –

+0

Loại đối tượng nào là hình ảnh biến? –

0

Bạn phải làm sống động khung của chế độ xem, để thu nhỏ khung hình từ không đến trạng thái cuối cùng. Điều này có thể được thực hiện ví dụ với hoạt ảnh khối UIView.

Vì vậy, ví dụ: bắt đầu với chế độ xem của bạn dưới dạng thuộc tính IBOutlet self.myView với kích thước và vị trí cuối cùng, nhưng đặt cờ ẩn. Sau đó, khi bạn muốn nó xuất hiện sử dụng như sau:

// Save old frame as final stater and set it to zero size for the start of the animation 
// But keep the same center position, so it just grows and don't move around 
CGRect oldFrame = self.myView.frame; 
CGRect oldCenter = self.myView.center; 

self.myView.frame = CGRectZero; 
self.myView.center = oldCenter; 

self.myView.hidden = NO; 

NSTimeInterval duration = 0.3; 

[UIView animateWithDuration:duration delay:0.0 options:UIViewAnimationOptionAllowUserInteraction animations:^{ 
       // New position and size after the animation should be the same as in Interface Builder 
       self.myView.frame = oldFrame 
    } 
        completion:^(BOOL finished){ 
               // You can do some stuff here after the animation finished 
        }]; 
+0

Điều đó ... có thể sẽ không hoạt động tốt. Hoạt ảnh khung hình của chế độ xem hình ảnh sẽ buộc nó tự vẽ lại ở mọi khung hình của hoạt ảnh. –

+1

@NoahWitherspoon sẽ là một biến đổi một cách tốt hơn? – Thyraz

+0

Yup. Hoạt ảnh từ CGAffineTransformMakeScale (0,01,0.01) đến CGAffineTransformIdentity sẽ thực hiện thủ thuật. –

0

Swift 2.0 phiên bản

view.transform = CGAffineTransformMakeScale(0.01, 0.01); 

    UIView.animateWithDuration(0.2, delay: 0, options: .CurveEaseOut, animations: {() -> Void in 
     // animate it to the identity transform (100% scale) 
     self.view.transform = CGAffineTransformIdentity; 

     }) { (finished) -> Void in 
     // if you want to do something once the animation finishes, put it here 
    } 
4

nếu bạn muốn một cái gì đó như Facebook thực hiện theo ý thích của bất kỳ bài đăng nào sau đó sử dụng

này
-(void)animateButton:(UIButton *)sender{ 
UIButton * btn = (UIButton *)sender; 
[UIView animateWithDuration:0.3/1.5 animations:^{ 
    btn.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.4, 1.4); // scales up the view of button 
} completion:^(BOOL finished) { 
    [UIView animateWithDuration:0.3/2 animations:^{ 
     btn.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.7, 0.7);// scales down the view of button 
    } completion:^(BOOL finished) { 
     [UIView animateWithDuration:0.3/2 animations:^{ 
      btn.transform = CGAffineTransformIdentity; // at the end sets the original identity of the button 
     }]; 
    }]; 
}];} 

chỉ cần gọi phương pháp này khi bạn muốn animate xem

nếu bạn có văn bản và hình ảnh trên nút và bạn chỉ muốn động hình ảnh của nút sau đó chỉ cần thay thế "btn" với "btn. imageView ", điều này sẽ chỉ tạo ra hình ảnh động trên thuộc tính xem hình ảnh của nút. Hy vọng điều này sẽ giúp Tất cả tốt nhất.

0

Để làm điều đó bạn sẽ phải sử dụng đơn giản UIView

Thêm chế độ xem UI vào chế độ xem hiện tại của bạn.

- (void) initPopUpView 
{ 
    popup.alpha = 0; 
    popup.frame = CGRectMake (160, 240, 0, 0); 
    [self.view addSubview:popup]; 
} 

- (void) animatePopUpShow 
{ 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.3]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationWillStartSelector:@selector(initPopUpView)]; 

    popup.alpha = 1; 
    popup.frame = CGRectMake (20, 40, 300, 400); 

    [UIView commitAnimations]; 
} 
Các vấn đề liên quan