簡體   English   中英

自定義搜索后,源ViewController閃爍

[英]Source ViewController flashing after custom segue

我試圖在兩個視圖控制器之間進行自定義選擇。 一切正常,除了動畫結束時,我可以看到源ViewController短暫地閃爍(很短)。 這並非每次都會發生。

.h文件:

#import <UIKit/UIKit.h>

@interface HorizontalSegue : UIStoryboardSegue

@property CGPoint originatingPoint;

@end

.m文件:

#import "HorizontalSegue.h"

@implementation HorizontalSegue

- (void)perform {
    UIViewController *sourceViewController = self.sourceViewController;
    UIViewController *destinationViewController = self.destinationViewController;

    // Add the destination view as a subview, temporarily
    [sourceViewController.view addSubview:destinationViewController.view];

    // Store original centre point of the destination view
    CGPoint originalCenter = destinationViewController.view.center;

    // Set center to start point of the button
    destinationViewController.view.center = CGPointMake(self.originatingPoint.x*3, self.originatingPoint.y);

    [UIView animateWithDuration:0.5
                          delay:0.0
                        options:UIViewAnimationOptionCurveEaseInOut
                     animations:^{
                         destinationViewController.view.center = originalCenter;
                     }
                     completion:^(BOOL finished){
                         [destinationViewController.view removeFromSuperview]; // remove from temp super view
                         [sourceViewController presentViewController:destinationViewController animated:NO completion:NULL]; // present VC
                     }];
}

@end

有沒有辦法擺脫這種閃光? 我已經嘗試過針對類似問題提出的一些解決方案,但是沒有任何效果。

您不應該像這樣顯示viewcontroller,將目標的子視圖添加到當前視圖中,並使用它們進行動畫處理。 從一個控制器過渡到另一個控制器時,SDK需要執行很多邏輯,因此遵循Apple指南很重要。

從iOS7.0開始,有一種全新的方法可以通過UIViewControllerTransitioningDelegate(這是所有UIViewControllers的@property)來顯示帶有動畫的控制器,該動畫使您可以執行任何類型的動畫。

有很多這樣的教程

http://www.teehanlax.com/blog/custom-uiviewcontroller-transitions/

但是,如果您希望保留手動嵌入控制器的舊方法,則應在此處選中“添加和刪除子代”: https//developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/CreatingCustomContainerViewControllers/CreatingCustomContainerViewControllers。 html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM