在过渡期间,CATransition褪色为黑色

时间:2017-04-07 07:06:08

标签: ios swift catransition

我正在两个视图控制器上执行简单的从右到左的转换。动画效果很好,完全符合我想要的效果。但是,由于呈现/呈现的视图控制器淡入/淡出,我在后台获得了黑色闪光。

我的转型:

let transition = CATransition()
transition.duration = 2.25 // Slow duration to see the black.
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromRight
view.window!.layer.add(transition, forKey: kCATransition)
present(vc, animated: false, completion: nil)

我读到在AppDelegate中设置窗口颜色didFinishLaunchingWithOptions可以解决这个问题,但是,似乎没有做任何事情。 (在过渡期间,黑色仍然可见。)

self.window!.backgroundColor = UIColor.white

有关让两个VC在持续时间内没有黑色闪烁而转换的建议吗?感谢。

1 个答案:

答案 0 :(得分:1)

我在SegueFromBottom内执行自定义转换时遇到了完全相同的问题。我在阅读A Beginner’s Guide to Animated Custom Segues in iOS 8后设法解决了这个问题。

在故事板中选择您的segue,选择自定义类并应用自定义import UIKit class SegueFromBottom: UIStoryboardSegue { override func perform() { // Assign the source and destination views to local variables. let firstVCView = self.source.view as UIView! let secondVCView = self.destination.view as UIView! // Get the screen width and height. let screenWidth = UIScreen.main.bounds.size.width let screenHeight = UIScreen.main.bounds.size.height // Specify the initial position of the destination view. secondVCView?.frame = CGRect(x: 0.0, y: screenHeight, width: screenWidth, height: screenHeight) // Access the app's key window and insert the destination view above the current (source) one. let window = UIApplication.shared.keyWindow window?.insertSubview(secondVCView!, aboveSubview: firstVCView!) // Animate the transition. UIView.animate(withDuration: 0.4, animations: { () -> Void in firstVCView?.frame = (firstVCView?.frame.offsetBy(dx: 0.0, dy: -screenHeight))! secondVCView?.frame = (secondVCView?.frame.offsetBy(dx: 0.0, dy: -screenHeight))! }, completion: { (Finished) -> Void in self.source.present(self.destination as UIViewController, animated: false, completion: nil) }) } } 类:

enter image description here

以下是Swift 3的更新代码。

<FrameLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.apurata.apurataapplication.Activity.MainActivity"
android:id="@+id/parentMainActivity">
<ScrollView
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:animateLayoutChanges="true">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:weightSum="1">
        <Button
            android:id="@+id/btnGetDni"
            android:text="@string/takePicture"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <ImageView
            android:id="@+id/imgViewGetDni"
            android:layout_width="320dp"
            android:layout_marginLeft="20dp"
            android:layout_height="250dp" />

           <Button
            android:id="@+id/btnGetSign"
            android:text="@string/takePicture"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
            <ImageView
            android:id="@+id/imgViewGetSign"
            android:layout_width="320dp"
            android:layout_height="250dp" />
           <Spinner
            android:id="@+id/listOptions"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
            <android.support.design.widget.TextInputLayout
            android:id="@+id/lblVerificationCode"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dp"
            android:layout_marginTop="20dp">
         <Button
            android:id="@+id/btnStart"
            style="@style/buttonStyle"
            android:text="@string/start"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
           </LinearLayout>
</ScrollView>
<LinearLayout
    android:id="@+id/linearlLoading"
    android:layout_width="300dp"
    android:layout_height="300dp"
    android:layout_gravity="center"
    android:orientation="vertical"
    android:animateLayoutChanges="true"
    android:visibility="gone">

    <LinearLayout
        android:layout_marginTop="70dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_gravity="center"
        android:weightSum="1">

        <TextView
            android:layout_gravity="center_horizontal"
            android:id="@+id/txtLoading"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="Cargando"
            android:layout_weight="0.59" />

        <com.wang.avi.AVLoadingIndicatorView
            android:id="@+id/avi"
            android:layout_gravity="center_horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:indicatorName="PacmanIndicator"
            app:indicatorColor="@color/green_A700"
            style="@style/AVLoadingIndicatorView.Large"
            />

    </LinearLayout>
</LinearLayout>
</FrameLayout>