iOS偽轉場動畫

FilomenaBri 8年前發布 | 8K 次閱讀 iOS開發 移動開發

iOS偽轉場動畫

  • 通過modal進行轉場,設置 modalTransitionStyle 為 UIModalTransitionStyleCrossDissolve ,設置 modalPresentationStyle 為 UIModalPresentationOverFullScreen

圖片放大縮小的效果

外部只需要傳入一個外部的 UIImageView 即可

1.創建一個 UIImageView 和一個 CGRect 來保存圖片信息和圖片frame信息。

使用 - (CGRect)convertRect:(CGRect)rect toView:(nullable UIView *)view; 方法來獲取圖片的相對位置。

2.視圖將要出現時做動畫效果

- (void)viewWillAppear:(BOOL)animated{
        [super viewWillAppear:animated];
        [UIView animateWithDuration:AnimationTime animations:^{       
        //這里可以自由發揮了
        self.view.backgroundColor = [UIColor greenColor];self.currentIV.frame = CGRectMake(0, 0, 200, 200);   self.currentIV.center = CGPointMake(self.view.center.x, 200);
        } completion:^(BOOL finished) {
        }];
    }

3.返回的點擊事件處理

- (void)back{
    [UIView animateWithDuration:AnimationTime animations:^{
        if ([self.type isEqualToString:@"vv"]) {
            self.view.center = CGPointMake(self.view.center.x, self.view.bounds.size.height*1.5);
        }else {
            self.currentIV.frame = self.oldFrame;
            self.view.backgroundColor = [UIColor clearColor];
        }
    } completion:^(BOOL finished) {
        [self dismissViewControllerAnimated:NO completion:nil];
    }];

}</code></pre>

4.就這樣,效果就出來啦

Boss直聘動畫效果

用的是截屏的方法來實現背景縮小后置的效果

1.在當前 UIViewController 用一個 UIImageView 來保存截圖

-(UIImage *)screenImageWithSize:(CGSize )imgSize{
    UIGraphicsBeginImageContext(imgSize);
    CGContextRef context = UIGraphicsGetCurrentContext();

AppDelegate * app = (AppDelegate *)[UIApplication sharedApplication].delegate; //獲取app的appdelegate,便于取到當前的window用來截屏
[app.window.layer renderInContext:context];

UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;

}</code></pre>

2.在下一個VC創建一個減方法,在當前VC中使用

[self presentViewController:vc animated:NO completion:nil];

[UIView animateWithDuration:0.3 animations:^{
//當前VC下截圖的縮小效果
    self.screenshot.bounds = CGRectMake(50, 50, SCREEN.width - 100, SCREEN.height - 100);
} completion:^(BOOL finished) {
//這就是減方法 =_= 動畫結束時,改變背景塊的frame
    [vc changeBigView];
}];</code></pre> 

3.在下一個VC返回時,當前VC的截圖視圖移除。

[weakSelf.screenshot removeFromSuperview];

4.這樣,BOSS直聘的動畫效果就出現了。

按以上思路,就可以實現一些簡單常見的動畫效果^0^

 

來自:http://www.jianshu.com/p/18549d27fe0e

 

 本文由用戶 FilomenaBri 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!