这是测试项目中主视图控制器的viewDidLoad:
- (void)viewDidLoad
Run Code Online (Sandbox Code Playgroud)
{[super viewDidLoad];
UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 300, 300)];
[self.view addSubview:containerView];
UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
[redView setBackgroundColor:[UIColor redColor]];
[containerView addSubview:redView];
UIView *yellowView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
[yellowView setBackgroundColor:[UIColor yellowColor]];
[UIView transitionWithView:containerView duration:3
options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
[redView removeFromSuperview];
[containerView addSubview:yellowView];
}
completion:NULL];
}
Run Code Online (Sandbox Code Playgroud)
刚出现黄色框.没有动画,无论我尝试哪种UIViewAnimationOption.为什么???
编辑:我也尝试使用performSelector withDelay将动画移出viewDidLoad并转移到另一个方法.相同的结果 - 没有动画.
还试过这个:[UIView transitionFromView:redView toView:yellowView duration:3选项:UIViewAnimationOptionTransitionFlipFromLeft completion:NULL];
尽管如此,黄色视图才会出现.没有动画.
我有一个图像墙(UIScrollView),在那里我有很多UIImageView's.
这是我的代码:
for (ThumbPosterModel *tPoster in _thumbsPosterStack) {
UIImageView *imageView = [[UIImageView alloc] initWithImage:tPoster.thumb];
imageView.userInteractionEnabled = YES;
imageView.frame = CGRectMake(i, imageView.frame.origin.y, imageView.frame.size.width, imageView.frame.size.height);
[tPoster setTag:tag];
[_posterTagArr addObject:(BasicPosterModel*)tPoster];
imageView.tag = tag;
tag++;
[posterWallScrollView addSubview:imageView];
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageDoubleTapped:)];
doubleTap.numberOfTapsRequired = 2;
[imageView addGestureRecognizer:doubleTap];
}
Run Code Online (Sandbox Code Playgroud)
这是我的IBAction:
-(IBAction)imageDoubleTapped:(id)sender {
NSInteger selectTag = (((UIGestureRecognizer*)sender).view.tag);
for (BasicPosterModel *bPoster in _posterTagArr) {
if(bPoster.tag == selectTag) {
[UIView transitionFromView:(UIImageView*)((UIGestureRecognizer*)sender).view
toView:mySecordView //let's say next ImageView. Doesn't matter
duration:1.0
options:UIViewAnimationOptionTransitionCrossDissolve
completion:^(BOOL finished) …Run Code Online (Sandbox Code Playgroud) objective-c uiviewanimation uiviewanimationtransition ios uiviewanimation-curve
我使用iOS 7引入的新自定义过渡,我试图将视图从我的'主'视图控制器移动到我的'详细'视图控制器中的视图,类似于Photos.app放大照片时的方式你点击它,除了详细视图中的这个视图只占用屏幕的一半.要做到这一点,我试图通过从细节或toViewController获取最终帧来将此视图设置为最终帧的动画.然而,我得到的框架是来自Interface Builder的toViewController视图的起始框架,而不是AutoLayer在其上传递后出现的视图.如何通过自动布局设置框架后获取框架?我在toViewController特殊视图框架返回animateTransition之前尝试了[self.view layoutSubviews]:但仍然给出了IB布局.
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
UIViewController* toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIViewController* fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
[[transitionContext containerView] addSubview:toViewController.view];
toViewController.view.alpha = 0;
[UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
fromViewController.view.alpha = 0;
toViewController.view.alpha = 1;
fromViewController.specialView = [toViewController detailSpecialViewFrame];
} completion:^(BOOL finished) {
[transitionContext completeTransition:![transitionContext transitionWasCancelled]];
}];
}
Run Code Online (Sandbox Code Playgroud) 我有一个带有嵌入式子视图控制器的父视图控制器.当用户点击孩子时,我想在全屏模式下使用"扩展帧"动画呈现其视图.例如,类似的UI范例用于缩放Facebook和9GAG应用中的图片.
我是否应该为全屏模式演示创建一个新的控制器并将其设置为动画,好像它只是在子视图控制器之上?或者我应该为孩子的视图设置动画以扩展到超视图的界限?
我听说过UIStoryboardSegue和的自定义子类UIViewControllerTransitioning.这些方法适用于我的情况吗?
完成此任务的最佳方法是什么?
提前致谢.皮特.
PS解决了这个问题之后,我想通过交互式缩放到缩放手势来扩展我的过渡.如果用户用两根手指触摸子视图,则帧动画会对点击做出反应.当用户将手指放开时,动画应该还原,将子视图返回到其原始帧,或者继续,就像用户点击视图一样.
我试图在Facebook的照片集合视图中显示这种效果:
我的目标是:
我已经完成了淡出工作,但动画效果最差.
我的CollectionView:
import UIKit
class Feed: UIViewController, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {
var collectionView: UICollectionView?
var myArray = ["cool", "neat", "fun", "cool", "neat", "fun", "cool", "neat", "fun", "cool", "neat", "fun", "cool", "neat", "fun", "cool", "neat", "fun", "cool", "neat", "fun", "cool", "neat", "fun"]
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.yellowColor()
self.title = "Feed"
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
layout.sectionInset = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
layout.itemSize = …Run Code Online (Sandbox Code Playgroud) 使用UIView.transitionFromView后,"fromView"会发生什么?你怎么回来的?(重新初始化它?).
这是我制作的一个简单示例,当我尝试返回"fromView"或引用其上的标签等时,出现"致命错误:在展开可选值时意外发现nil".
假设我在我的故事板中设置了这些视图 - 我在根目录中添加了一个名为"cardView"的子视图,然后在cardView下添加了一个名为"backView"和"frontView"的视图
将它们链接到视图控制器并将"翻转"按钮链接到看起来像这样的动作(以及变量):
@IBOutlet weak var backView: UIView!
@IBOutlet weak var frontView: UIView!
@IBOutlet var cardView: UIView!
var front = true
@IBAction func flipIt(sender: AnyObject) {
if front {
UIView.transitionFromView(self.frontView, toView: self.backView, duration: 1, options: UIViewAnimationOptions.TransitionFlipFromRight, completion: nil)
} else {
UIView.transitionFromView(self.backView, toView: self.frontView, duration: 1, options: UIViewAnimationOptions.TransitionFlipFromLeft, completion: nil)
}
front = !front
}
Run Code Online (Sandbox Code Playgroud)
因此,当我运行它时 - 第一次点击"翻转"按钮就可以了,它会翻转到backView,但是当我再次点击它时,我得到"致命错误:在第二次打开一个可选值时意外发现nil" transitionFromView行("else"下的那行).
显然,我不理解transitionFromView的一些影响.我已经尝试了很多不同的东西,包括使用这种转换的教程,并且能够使它工作,但它不使用故事板,所以我不知道如何应用它对我的故事板视图的影响,显然......
谢谢你的帮助.
我正在进行子类化UIPresentationController以创建弹出窗口的自定义演示文稿/转换UIViewController.弹出视图本身应该被限制在呈现视图控制器的框架中.我可以用手动框架计算来完成它,但在我看来它会非常繁琐且容易出错.
看看UIPresentationController它的API 看起来强烈强制使用CGSize's和CGRect's并坚持让你混合和匹配'准自动布局'方法systemlayoutSizeFitting和其他人一样,并且完全令人困惑.我不知道哪些方法需要被覆盖,何时存在视图,何时添加它们,哪些覆盖返回值优先于其他返回值.它基本上是一场噩梦.
如果有的话,最简单的方法是使用我在这个API中使用的传统的基于约束的布局?
uiviewcontroller uikit uiviewanimationtransition autolayout uipresentationcontroller
我有一个视图控制器,在其视图的给定区域中显示2个子视图控制器的视图.2个子视图控制器是FlopVC和FipVC.
我想动画从一个子视图到另一个子视图的过渡.我正在使用的代码是:
-(IBAction)flip:(id)sender{
UIViewController *newVC = nil;
if (self.isFlip) {
newVC = [[FlopVC alloc] initWithNibName:nil bundle:nil];
}else{
newVC = [[FipVC alloc] initWithNibName:nil bundle:nil];
}
newVC.view.frame = CGRectMake(120, 20, 240, 260);
[self.view addSubview:newVC.view];
[UIView transitionFromView:self.currentVC.view
toView:newVC.view
duration:0.9
options:UIViewAnimationTransitionFlipFromLeft
completion:^(BOOL finished) {
self.currentVC = newVC;
self.isFlip = ! self.isFlip;
}];
}
Run Code Online (Sandbox Code Playgroud)
子视图被交换,但没有任何动画.我究竟做错了什么?
PS完整项目在这里.
cocoa-touch core-animation objective-c uiview uiviewanimationtransition
我正在尝试自定义演示动画,但VC是一个MPMoviePlayerViewController.我正在学习本教程:
当我出席时MPMoviePlayerViewController,一切都是对的.
但是当我解雇它时,只需要方法:
- (id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed
Run Code Online (Sandbox Code Playgroud)
不叫,我做错了什么?
这是代码:
- (IBAction)playButtonTouchedIn:(id)sender {
NSURL *url = [[NSBundle mainBundle]URLForResource:@"Learn to speak Spanish quickly with funny videos on youtube" withExtension:@"mp4"];
MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
player.transitioningDelegate = self;
player.modalTransitionStyle = UIModalPresentationCustom;
[player.moviePlayer setShouldAutoplay:NO];
player.moviePlayer.controlStyle = MPMovieControlStyleNone;
[self presentViewController:player animated:YES completion:^{
[player.moviePlayer play];
player.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
}];
}
Run Code Online (Sandbox Code Playgroud)
该UIViewControllerTransitioningDelegate方法:
- (id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController: (UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source
{
self.presenting = YES;
return self;
}
- (id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController …Run Code Online (Sandbox Code Playgroud) 我正在寻找如何实现像WhatsApp单元格滑动,我已经使用UIPanGestureRecognizer实现了单元格滑动动画,唯一的左边是执行交互式动画 - 将新内容添加UIViewController到窗口并根据手势识别器速度和X显示它 - 轴值 - .
关于我想要达到的目标,还有一些额外的说明是准确的:
我有一个UITableViewController,其中有自定义UITableViewCell.我希望能够从左向右拖动单元格以启动交互式动画.(注意:我已经实现了细胞扫描).
新的UIViewController将从左侧推出.
在滑动单元格的同时,UITableViewController视图将向右移动,此时,我想显示UIViewController它旁边的推动.
这里有一个GIF,可以了解我需要的更多细节(GIF从右向左滑动单元格,我需要相反):
ios ×7
objective-c ×4
swift ×3
uiview ×3
autolayout ×2
animation ×1
cocoa-touch ×1
ios7 ×1
iphone ×1
swift3 ×1
uikit ×1
zoom ×1