我已经提到了这个问题以及关于视图/视图控制器转换的几个问题,但仍然找不到满意的答案.大多数解决方案建议翻转视图而不是视图控制器.但是,我的应用程序中的两个视图控制器具有完全不同的操作和实现逻辑,因此我避免将它们混合在一起.
在我的应用程序中,我有一个FrontViewController嵌入在NavigationController中的模态视图控制器.在视图上按下一个按钮后,模态视图控制器应该翻转BackViewController,反之亦然.我曾经尝试过以下方面FrontViewController:
let navi = UINavigationController(rootViewController: backController)
navi.modalPresentationStyle = .CurrentContext
navi.modalTransitionStyle = .FlipHorizontal
self.presentViewController(backController, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
这几乎和我想要的一样,除了翻转导航栏之外.此外,如果我关闭模态视图,只有堆栈顶部的视图控制器被解除,而我无法让正确的父/呈现控制器解除模态视图中的所有其他堆栈控制器.
因此,我还试图阻止的ViewController栈并使用transitionFromViewController在FrontViewController使用相同的导航控制器代替:
self.navigationController!.addChildViewController(backController)
self.willMoveToParentViewController(nil)
self.navigationController!.transitionFromViewController(self, toViewController: backViewController, duration: 1, options: .TransitionFlipFromLeft, animations: {}, completion: ({Bool -> Void in
self.removeFromParentController()
c.didMoveToParentViewController(self)
}))
Run Code Online (Sandbox Code Playgroud)
然后我在执行时遇到了这个运行时错误: Parent view controller is using legacy containment in call to -[UIViewController transitionFromViewController:toViewController: duration:options:animations:completion:]
那么,如何在两个视图控制器之间进行转换同时防止它们保留在视图控制器堆栈中?
uiviewcontroller uinavigationcontroller uiviewanimationtransition ios swift
我试图让UIView向上滑动四分之一的页面以显示其下方的另一个视图(显示选项),然后向下滑动以覆盖这些选项.我无情地搜索过,但似乎无法找到我正在寻找的东西.我不想使用模态视图,因为我想在屏幕上保持顶视图.在下面的代码中,我有点工作,顶层向上滑动,但随后完全消失(淡出).
任何帮助是极大的赞赏!
谢谢.
HomeOptionsViewController *homeOptionsViewController = [[HomeOptionsViewController alloc]
initWithNibName:@"HomeOptionsViewController"
bundle:nil];
// get the view that's currently showing
UIView *currentView = self.view;
// get the the underlying UIWindow, or the view containing the current view
UIView *theWindow = [currentView superview];
UIView *newView = homeOptionsViewController.view;
//newView.frame = CGRectMake(0,300, 320,140);
newView.frame = CGRectMake(0,-10, 320,140);
// remove the current view and replace with myView1
//---[currentView removeFromSuperview];
[theWindow addSubview:newView];
theWindow.frame = CGRectMake(0,-110,320,200);
newView.frame = theWindow.bounds;
// set up an animation for the transition between the …Run Code Online (Sandbox Code Playgroud) iphone core-animation uiview catransition uiviewanimationtransition
我正在尝试制作一个简单的西蒙游戏(不断增加的颜色序列闪烁,用户必须尝试重复该序列).我正在进行的方式是通过4个UIViews和8个图像.所以有一个红色,蓝色,绿色和黄色的UIView.我有深绿色,浅绿色,深红色,浅红色等GIF.
所以在我的代码中,我正在使用UIView的transitionWithView动画块:UIView imageView.image默认为暗色图像,这个块正在转换为浅色图像,并在完成时返回到深色图像(给它一个"照亮"的外观).
- (void) animateColor:(NSString *)color
{
...
//do stuff to default the dark and light image name and which UIView to animate based on the color parameter
...
[UIView transitionWithView:imageView
duration:.5
options: UIViewAnimationOptionTransitionCrossDissolve | UIViewAnimationOptionAutoreverse
animations:^{
imageView.image = [UIImage imageNamed:lightImage];
}
completion:^(BOOL finished){
if (finished){
imageView.image = [UIImage imageNamed:darkImage];
}
}];
}
Run Code Online (Sandbox Code Playgroud)
当我用一种颜色称它为此代码的方法时,这工作正常.
问题是,我说我有一个NSArray或颜色,我想顺序动画.因此,如果我的数组是"蓝色","绿色",我希望使用蓝色调用transitionWithView,为蓝色视图设置动画,然后为绿色视图设置动画.现在,它将同时为绿色视图和蓝色视图设置动画.
我现在正试着玩NSTimer,但没有太多运气.
任何建议将非常感谢.
objective-c uiview uiviewanimation uiviewanimationtransition
我有UIViewControllersA和B,他们被分配AppDelegate.我需要对它们进行过渡.如何在不重新分配和更换的情况下过境UIViews?这段代码来自我的UIBarButtonItemin UINavigationController:
[UIView transitionFromView:self.view //UIViewController A
toView:appDelegate.secondViewController.view //UIViewController B
duration:0.5
options:UIViewAnimationOptionTransitionFlipFromLeft
Run Code Online (Sandbox Code Playgroud)
这个方法取代UIViews了我UIViewControllers,我可以将它们转回,或者只是不知道该怎么做.你能告诉我怎么做吗?
objective-c uiviewcontroller uiview uiviewanimationtransition ios
我正在尝试在 iPad 上实现一些自定义转换,但我遇到了一些问题。由于X,Y坐标不总是在左上角开始containerView的transitionContext,当设备旋转我写了下面的方法
- (CGRect)rectForPresentedStateStart:(id<UIViewControllerContextTransitioning>)transitionContext
{
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIView *containerView = [transitionContext containerView];
switch (fromViewController.interfaceOrientation)
{
case UIInterfaceOrientationLandscapeRight:
return CGRectMake(0, containerView.bounds.size.height,
containerView.bounds.size.width, containerView.bounds.size.height * 2 / 3);
case UIInterfaceOrientationLandscapeLeft:
return CGRectMake(0, - containerView.bounds.size.height * 2 / 3,
containerView.bounds.size.height, containerView.bounds.size.height * 2 / 3);
case UIInterfaceOrientationPortraitUpsideDown:
return CGRectMake(- containerView.bounds.size.width * 2 / 3, 0,
containerView.bounds.size.width * 2 / 3, containerView.bounds.size.height);
case UIInterfaceOrientationPortrait:
return CGRectMake(containerView.bounds.size.width, 0,
containerView.bounds.size.width * 2 / 3, containerView.bounds.size.height);
default:
return CGRectZero; …Run Code Online (Sandbox Code Playgroud) 我已经UIViewControllerAnimationTransition创建了一个自定义类,并且需要UITabBarController在切换选项卡时使其成为动画.
但是,tabBarController它不使用常规标签栏.我有一个类似于它的自定义实现,当按下按钮时,它会调用以下代码:
tabBarController.selectedIndex = index
Run Code Online (Sandbox Code Playgroud)
目前我有tabBarController(子类)作为自己的委托transitionDelegate.但是,委托方法animationControllerForPresentedController实际上从未被调用过.
标签栏控制器是否可以成为自己的委托?如果是这样,为什么转换代码永远不会被调用?
我正在尝试学习一些新的iOS编程模式.我已经阅读了一些关于在iOS 7中添加的UIViewController转换API的内容.它们看起来很酷但是对于看起来更简单的任务也感觉非常沉重.
考虑这个用例:我有一个管理"幻灯片"的自定义容器视图控制器.它包含一系列幻灯片视图控制器,用户可以通过点击按钮向前和向后移动它们.
我可以按如下方式实现此过渡:
private func transitionToViewController(viewController: UIViewController, direction: TransitionDirection = .Forward, animated: Bool = true) {
currentViewController.willMove(toParentViewController: nil)
addChildViewController(viewController)
// ... set up frames, other animation prep ...
contentContainerView.addSubview(comingView)
UIView.animate(duration: 0.5, animations: {
// do the animations
}) { (finished) in
leavingView.removeFromSuperview()
self.currentViewController.removeFromParentViewController()
viewController.didMove(toParentViewController: self)
// final clean up
}
}
Run Code Online (Sandbox Code Playgroud)
新的转换API将如何改善这一点?据我所知,如果您正在滚动自己的容器视图控制器,这些API使用起来会更加复杂(请参阅自定义容器视图控制器转换.
转换API中的值主要用于交互式转换吗?
谢谢你的澄清
我正在学习本教程,以了解如何为UIViewControllers进行交互式转换.
一切正常,但我发现有些闪烁.
我发现的第一个闪烁发生在你从右向左拖动屏幕时.这是因为平移手势将识别每次拖动并运行该panned(_:)方法,并将弹出或执行segue来更改控制器.我修复了id添加委托方法的问题gestureRecognizerShouldBegin(_:).
这确保了如果从右向左拖动,则手势永远不会开始(.Begin).
但现在我有一个不同的问题.如果我从左向右拖动(按预期)但不中断拖动,则从右向左改变方向,应取消转换.在这种情况下,在旧控制器再次出现之前,我可以看到新控制器的短暂闪烁.
如何优雅地取消交互式动画?
这是一个试图显示问题的视频.我找不到减慢这个动画的方法所以它非常快.
编辑
我试过两种不同的方法.
这其中使用CABasicAnimation到过渡动画效果.而这一个使用animateWithDuration(_:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion:)
每当我打电话时,它们都会闪烁 cancelInteractiveTransition
我有一些自定义模式呈现和自定义控制器要呈现(UIViewController 的子类)。它是它自己的转换委托,并返回一些动画转换对象和表示控制器。我使用动画过渡对象在呈现时将呈现的视图添加到容器视图,并在关闭时将其删除,当然还可以对其进行动画处理。我使用演示控制器添加一些辅助子视图。
public final class PopoverPresentationController: UIPresentationController {
private let touchForwardingView = TouchForwardingView()
override public func presentationTransitionWillBegin() {
super.presentationTransitionWillBegin()
self.containerView?.insertSubview(touchForwardingView, atIndex: 0)
}
}
public final class PopoverAnimatedTransitioning: NSObject, UIViewControllerAnimatedTransitioning {
func setupView(containerView: UIView, presentedView: UIView) {
//adds presented view to container view
}
public func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
//1. setup views
//2. animate presentation or dismissal
}
}
public class PopoverViewController: UIViewController, UIViewControllerTransitioningDelegate {
init(...) {
...
modalPresentationStyle = .Custom
transitioningDelegate = self
}
public func animationControllerForPresentedController(presented: UIViewController, presentingController …Run Code Online (Sandbox Code Playgroud) uikit uiviewanimationtransition ios presentviewcontroller uipresentationcontroller
我有一个类似Tinder界面的应用程序,用户可以翻转汽车
在我ViewController.swift,我有
private var currentCardsOnScreen: [CardViewController] = []
当我将CardViewControllers放入堆栈时,此数组将被填充:
if !currentCardsOnScreen.map({ $0.id }).contains(vc.id) {
self.currentCardsOnScreen.append(vc)
}
Run Code Online (Sandbox Code Playgroud)
滑动后,项目会被删除:
if let index = currentCardsOnScreen.index(of: currentCard),
currentCardsOnScreen.map({ $0.id }).contains(currentCard.id) {
currentCardsOnScreen.remove(at: index)
}
Run Code Online (Sandbox Code Playgroud)
当用户选择卡时,我运行:
guard let currentCard = currentCard(index: index) else { return }
currentCard.flipCard()
Run Code Online (Sandbox Code Playgroud)
哪个调用此方法:
func flipCard() {
guard
let frontOfCard = frontOfCard,
let backOfCard = backOfCard
else { return }
UIView.animate(withDuration: 0.32, delay: 0, options: .transitionFlipFromRight, animations: {
if self.frontIsShowing {
self.view.transform = CGAffineTransform(scaleX: 1, y: 1) …Run Code Online (Sandbox Code Playgroud) ios ×8
swift ×5
uiview ×4
objective-c ×2
animation ×1
catransition ×1
iphone ×1
transitions ×1
uikit ×1
xcode6 ×1