2013-07-21 67 views

回答

0

一種方法是創建視圖的圖像,把它放在屏幕(在圖像視圖)在實際的視圖,設置視圖的alpha爲0 ,設置其框架(或調整佈局約束)以將其放置在新的位置,然後啓動淡出圖像的動畫,並淡入實際視圖。

像這樣的東西應該工作:

#import "ViewController.h" 
#import <QuartzCore/QuartzCore.h> 

@interface ViewController() 
@property (weak,nonatomic) IBOutlet UIView *fadingView; 
@property (weak,nonatomic) IBOutlet NSLayoutConstraint *topCon; 
@property (strong,nonatomic) UIImageView *iv; 
@end 

@implementation ViewController 

-(IBAction)moveView:(id)sender { 
    UIImage *viewimage = [self imageWithView:self.fadingView]; 
    self.iv = [[UIImageView alloc] initWithFrame:self.fadingView.frame]; 
    self.iv.image = viewimage; 
    [self.view addSubview:self.iv]; 
    self.fadingView.alpha = 0; 
    self.topCon.constant = 200; // topCon is IBOutlet to the top constraint to the superview 

    [UIView animateWithDuration:1 animations:^{ 
     self.fadingView.alpha = 1; 
     self.iv.alpha = 0; 
    } completion:^(BOOL finished) { 
     [self.iv removeFromSuperview]; 
    }]; 
} 

- (UIImage *)imageWithView:(UIView *)view { 
    UIGraphicsBeginImageContextWithOptions(CGSizeMake(view.bounds.size.width, view.bounds.size.height), view.opaque, [[UIScreen mainScreen] scale]); 
    [view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
    UIImage * img = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    return img; 
} 
0

是沿着這些路線的東西:

[UIView animateWithDuration:0.25 animations:^{ 

    self.viewA.frame = CGRectMake... // middle point 
    self.viewA.alpha = 0.0f; 

    }completion:^ (BOOL finished) 
{ 
    [UIView animateWithDuration:0.25 animations:^{ 

    self.viewA.frame = CGRectMake... // final point 
    self.viewA.alpha = 1.0f; 
    }]; 
}]; 
+0

但這最終只是淡出了出來。我需要另一個動畫來淡化它。 – circuitlego

+0

你可以連鎖動畫,所以你有淡出,直到X位置和淡入淡出,直到最後destionation。 – Peres

+0

檢查我的編輯.. – Peres

相關問題