简体   繁体   English

斯威夫特:transitionFromView翻转整个屏幕而不是视图

[英]Swift: transitionFromView flip whole screen instead of view

I have a weird issue with swift. 我有个奇怪的问题。 I am trying to flip two views, not the whole screen but it flips the whole screen. 我试图翻转两个视图,而不是整个屏幕,但它翻转了整个屏幕。

It has been asked before on here but no answer: 在此之前有人问过,但没有答案:

flip animation in swift flips whole view not subviews 快速翻转动画将整个视图而不是子视图翻转

This is the references to the views I have (I have confirmed they only take up part of the screen): 这是对我所拥有的视图的引用(我已经确认它们仅占据屏幕的一部分):

@IBOutlet var frontview: UIView!
@IBOutlet var backview: UIView!

And this is my code for flipping: 这是我的翻转代码:

func flipCard() { 

   if (showingBack) {
        UIView.transitionFromView(backview, toView: frontview, duration: 1, options: UIViewAnimationOptions.TransitionFlipFromRight, completion: nil)
        showingBack = false
    } else {
        UIView.transitionFromView(frontview, toView: backview, duration: 1, options: UIViewAnimationOptions.TransitionFlipFromLeft, completion: nil)
        showingBack = true
    }       
}

Thanks for your help 谢谢你的帮助

Try This example. 试试这个例子。 I think you are looking something like this. 我想你看起来像这样。 instead of imageView try UIView in your case. 代替imageView尝试使用UIView。

What happens when you call UIView.transitionFromView(backView, toView: frontView ... is it flips the parent of those two views. Presumably the parent in your case is the root view of the ViewController, so to get it to flip just those views instead of the "whole screen" you would just need to embed both backView and frontView in another view. 当您调用UIView.transitionFromView(backView, toView: frontView ...时会发生什么UIView.transitionFromView(backView, toView: frontView ...它会翻转这两个视图的父视图。 UIView.transitionFromView(backView, toView: frontView ...您的父视图是ViewController的根视图,因此要使其仅翻转那些视图而不是“整个屏幕”,您只需要在另一个视图中同时嵌入backViewfrontView

There's more details in this article. 本文中有更多详细信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM