Transisition 动画,多种思路
2017-10-18 本文已影响0人
BoxDeng
思路一: Transisition 动画 , 点击哪里,从那里弹出,铺满屏幕,
取代 Ctrl 的modal 模态 和 Navigation Ctrl 的 push 界面
照片 浏览器的 , DSImageShowView 的 两个 方法
法子挺笨的。都不是 Ctrl 层的。 在原Ctrl 的view 上添加 view.
通过 convertRect: toView: 获取坐标, 再 用 UIView 的 动画,来 呈现 Transition.
起码也要用 嵌套 视图 控制器嘛。
- (void)presentfromImageView:(UIView *)fromView toContainer:(UIView *)toContainer index:(NSInteger)index animated:(BOOL)animated completion:(void (^)(void))completion {
_fromView = fromView;
_toContainerView = toContainer;
NSInteger page = 0;
page = index;
if (index < 0 || index > 8) page = 0;
_hiddenView = fromView;
_hiddenView.hidden = YES;
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle: UIBlurEffectStyleLight ];
UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
effectView.frame = _blurBackground.bounds;
[_blurBackground addSubview:effectView];
self.size = _toContainerView.size;
self.blurBackground.alpha = 0;
self.pager.numberOfPages = self.items.count;
self.pager.currentPage = page;
[_toContainerView addSubview: self];
_scrollView.contentSize = CGSizeMake(_scrollView.width * self.items.count, _scrollView.height);
[_scrollView scrollRectToVisible:CGRectMake(_scrollView.width * page, 0, _scrollView.width, _scrollView.height) animated:NO];
[self scrollViewDidScroll: _scrollView];
[UIView setAnimationsEnabled:YES];
NSInteger currentPage = self.currentPage;
DSImageScrollView *scrollView = [self scrollViewForPage:currentPage];
DSImageScrollItem *item = _items[currentPage];
if (!item.thumbClippedToTop) {
NSString *imageKey = [[YYWebImageManager sharedManager] cacheKeyForURL:item.largeImageURL];
if ([[YYWebImageManager sharedManager].cache getImageForKey:imageKey withType:YYImageCacheTypeMemory]) {
scrollView.item = item;
}
}
if (!scrollView.item) {
scrollView.imageView.image = item.thumbImage;
[scrollView resizeSubviewSize];
}
CGRect fromFrame = [_fromView convertRect: _fromView.bounds toView:scrollView.imageContainerView];
[self presentAnimation:scrollView fromRect:fromFrame completion:^{
if (completion) completion();
}];
}
//present animation
- (void)presentAnimation:(DSImageScrollView *)scrollView fromRect:(CGRect)fromFrame completion:(void (^)(void))completion{
scrollView.imageContainerView.clipsToBounds = NO;
scrollView.imageView.frame = fromFrame;
scrollView.imageView.contentMode = UIViewContentModeScaleAspectFill;
_blurBackground.alpha = 1;
[UIApplication sharedApplication].keyWindow.windowLevel = UIWindowLevelStatusBar;
_scrollView.userInteractionEnabled = NO;
[UIView animateWithDuration:0.18 delay:0 options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut animations:^{
scrollView.imageView.frame = scrollView.imageContainerView.bounds;
scrollView.imageView.layer.transformScale = 1.01;
}completion:^(BOOL finished) {
[UIView animateWithDuration:0.18 delay:0 options:UIViewAnimationOptionBeginFromCurrentState|UIViewAnimationOptionCurveEaseInOut animations:^{
scrollView.imageView.layer.transformScale = 1.0;
_pager.alpha = 1;
}completion:^(BOOL finished) {
scrollView.imageContainerView.clipsToBounds = YES;
_isPresented = YES;
[self scrollViewDidScroll:_scrollView];
_scrollView.userInteractionEnabled = YES;
if (completion) completion();
}];
}];
}