簡體   English   中英

按下VC后,如何固定導航欄項目的動畫?

[英]How to fix Navigation Bar Item animating to side after pushing a VC?

我有一個iOS應用程序,正在為導航項創建自定義視圖。 每次進入屏幕時,導航項都很好用,並且放置正確。

在此處輸入圖片說明 但是,當從此屏幕上按下VC並返回到屏幕時,導航項會暫時顯示在正確的位置,但會立即移至右側角。

在此處輸入圖片說明

我確實懷疑這與過渡期間導航欄的動畫有關,但是即使嘗試了多種解決方法之后,它仍然會發生。 以下是導航項目視圖的代碼。

 UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 44)];
    v.backgroundColor = [UIColor clearColor];
    v.opaque = NO;

    UILabel *subtitleLabel = [[UILabel alloc] initWithFrame:CGRectIntegral(CGRectMake(v.bounds.origin.x, v.bounds.origin.y + v.bounds.size.height * 0.6, v.bounds.size.width, v.bounds.size.height * 0.3))];
    subtitleLabel.text = subtitle;
    subtitleLabel.font = [UIFont systemFontOfSize:11];//Font adjusted to accomodate text into size
    subtitleLabel.backgroundColor = [UIColor clearColor];
    subtitleLabel.opaque = NO;
    subtitleLabel.textAlignment = NSTextAlignmentCenter;
    subtitleLabel.textColor = defaultSubtitleTextColor;
    subtitleLabel.shadowOffset = defaultShadowOffset;
    subtitleLabel.shadowColor = defaultShadowColor;

    [v addSubview:subtitleLabel];


    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectIntegral(CGRectMake(v.bounds.origin.x, v.bounds.origin.y + v.bounds.size.height * 0.1, v.bounds.size.width, v.bounds.size.height * 0.5))];
    titleLabel.text = title;
    titleLabel.font = [UIFont boldSystemFontOfSize:19];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.opaque = NO;
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.textColor = defaultTextColor;
    titleLabel.shadowOffset = defaultShadowOffset;
    titleLabel.shadowColor = defaultShadowColor;

    [v addSubview:titleLabel];

    navItem.titleView = v;

在此上已經花費了很多時間,我們將不勝感激。

對於處於類似情況的其他人來說,這與intrinsicContentSize 設置后返回UILayoutFittingExpandedSize 問題不見了。

暫無
暫無

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

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