18

Tôi muốn thêm một chế độ xem phụ có hoạt ảnh. Tôi đang sử dụng thêm xem tiểu nên nó không hiển thị bất kỳ hình ảnh động vì vậy tôi muốn hiển thị bất kỳ hình ảnh động khi tôi đang làm điều này ... Tôi đang sử dụng mã dưới đây: -hiển thị hoạt ảnh khi addubview

UIViewController *vControllerHome = [[viewTemp alloc] initWithNibName:@"viewTemp" bundle:nil]; 
vControllerHome.view.frame =CGRectMake(0, 0, 320, 414); 
[self.view addSubview:vControllerHome.view]; 
self.selectedViewController = vControllerHome; 

Bất kỳ một thể đề nghị làm thế nào tôi làm điều này ?

Trả lời

38

Đây là mã .. Chỉ cần dùng thử.

PS: Thay thế myView bằng tên của chế độ xem bạn muốn thay thế.

CATransition *applicationLoadViewIn =[CATransition animation]; 
[applicationLoadViewIn setDuration:duration]; 
[applicationLoadViewIn setType:kCATransitionReveal]; 
[applicationLoadViewIn setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]]; 
[[myView layer]addAnimation:applicationLoadViewIn forKey:kCATransitionReveal]; 
26

ở đây là cho các khối hoạt hình

[UIView transitionWithView:containerView 
        duration:0.5 
       options:UIViewAnimationTransitionFlipFromRight //any animation 
      animations:^ { [containerView addSubview:subview]; } 
      completion:nil]; 
+2

Và để loại bỏ các subview? – djskinner

+1

Để xóa chế độ xem phụ, hãy sử dụng cùng một mã nhưng thay thế [containerView addSubview: subview]; với [self.view removeFromSuperview]; – rmooney

0

lẽ bạn có thể phân lớp UIView và override phương pháp willMove(toSuperview newSuperview: UIView?)

Dưới đây là ví dụ:

override public func willMove(toSuperview newSuperview: UIView?) { 
    super.willMove(toSuperview: newSuperview) 

    if let _ = newSuperview { 
     // This view will be added to some view 
     UIView.animate(withDuration: 0.2, delay: 0.0, usingSpringWithDamping: 0.6, initialSpringVelocity: 30.0, options: .curveEaseInOut, animations: { 
      //... 
     }, completion: { (finish) in 

     }) 
    } else { 
     // This view will be removed 
    } 
} 
Các vấn đề liên quan