iOS共享view动画简单实现(微博头条文章动画)
微博可能是修改了navigationcontroller的push动画, 没做具体研究...
想简单一点的话下列方法也可以, 基本就是个障眼法
场景: 点击tableview的cell后push一个控制器, 该控制器头部view有与该cell有相同的布局
解决: 把需要push的控制器加入当前view, 然后执行动画, 使之看起来和普通navigationcontroller下的控制器一样, 原frame为点击的cell的frame, 动画执行完毕后移除该控制器并且无动画push改控制器, 效果基本达到, navigationbar的动画因为无动画push导致变化地比较突兀, 此处手动加了一下动画.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
DDGiftListCell* cell = [self.tableView cellForRowAtIndexPath:indexPath];
DDPostDetailController* postDetail = [[DDPostDetailController alloc] init]];
[self addChildViewController:postDetail];
postDetail.view.frame = cell.frame;
[self.view addSubview:postDetail.view];
[UIView animateWithDuration:0.3 animations:^{
postDetail.view.frame = CGRectMake(0, self.tableView.contentOffset.y , self.view.width, self.view.height);
} completion:^(BOOL completed){
[postDetail.view removeFromSuperview];
[postDetail removeFromParentViewController];
//navigationbar添加动画
CATransition *transition = [CATransition animation];
transition.duration = 0.3f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFade;
[self.navigationController.navigationBar.layer addAnimation:transition forKey:nil];
[self.navigationController pushViewController:postDetail animated:NO];
}];
}