2017-09-24 9 views
15

透明なナビゲーションバーを作成すると、ios 11で機能しなくなりました。 テーブルビューがバーの下に表示されなくなるため、この黒いバーが上部に表示されます(ストーリーボードのインセットは適切に設定されています)。 0から始まる) 何が良いのでしょうか?ios 11の透明なナビゲーションバー

enter image description here

self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default) 
self.navigationController?.navigationBar.shadowImage = UIImage() 
self.navigationController?.navigationBar.isTranslucent = true 
+0

self.navigationController?.navigationBar.backgroundColor = UIColor.clearも追加しようとしましたか? – Tom

+0

はい、私はしました。同じ結果 –

+0

同じ結果 –

答えて

13

古い無効にしてみてください:

if (@available(iOS 11.0, *)) { 
    self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; 
} else { 
    self.automaticallyAdjustsScrollViewInsets = NO; 
} 

新しい:コードを追加し、あなたがのtableViewを使用している場合

automaticAdjustsScrの変更iOS11でollViewInsets:contentInsetAdjustmentBehaviorについて

@property(nonatomic,assign) BOOL automaticallyAdjustsScrollViewInsets 
API_DEPRECATED_WITH_REPLACEMENT("Use UIScrollView's 
contentInsetAdjustmentBehavior instead", ios(7.0,11.0),tvos(7.0,11.0)); 
// Defaults to YES 

typedef NS_ENUM(NSInteger, UIScrollViewContentInsetAdjustmentBehavior) { 
    UIScrollViewContentInsetAdjustmentAutomatic, // Similar to .scrollableAxes, but will also adjust the top & bottom contentInset when the scroll view is owned by a view controller with automaticallyAdjustsScrollViewContentInset = YES inside a navigation controller, regardless of whether the scroll view is scrollable 
    UIScrollViewContentInsetAdjustmentScrollableAxes, // Edges for scrollable axes are adjusted (i.e., contentSize.width/height > frame.size.width/height or alwaysBounceHorizontal/Vertical = YES) 
    UIScrollViewContentInsetAdjustmentNever, // contentInset is not adjusted 
    UIScrollViewContentInsetAdjustmentAlways, // contentInset is always adjusted by the scroll view's safeAreaInsets 
} API_AVAILABLE(ios(11.0),tvos(11.0)); 

/* Configure the behavior of adjustedContentInset. 
Default is UIScrollViewContentInsetAdjustmentAutomatic. 
*/ 
@property(nonatomic) UIScrollViewContentInsetAdjustmentBehavior contentInsetAdjustmentBehavior API_AVAILABLE(ios(11.0),tvos(11.0)); 

それはiOS11ためsafeAreaの問題である可能性があります。私は同じ問題に直面し、私はそれを解決することができました

#define adjustsScrollViewInsets_NO(scrollView,vc)\ 
do { \ 
    _Pragma("clang diagnostic push") \ 
    _Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \ 
     if ([UIScrollView instancesRespondToSelector:NSSelectorFromString(@"setContentInsetAdjustmentBehavior:")]) {\ 
      [scrollView performSelector:NSSelectorFromString(@"setContentInsetAdjustmentBehavior:") withObject:@(2)];\ 
     } else {\ 
      vc.automaticallyAdjustsScrollViewInsets = NO;\ 
     }\ 
    _Pragma("clang diagnostic pop") \ 
} while (0) 
7

私は似問題がありました。ストーリーボードのUIViewControllerに対して、「Extended Edges:Under Top/Bottom/Opaque Bar」を設定しました。 Like this. また、あなたが "Automatically Adjusts Scroll View Insets"

+0

私はすでに上下のチェックを受けていましたが、不透明ではありませんでした。 3つすべてをチェックして問題を解決しました。 –

4

: これはある専門家から定義してみてください。 は、ここで私のためにどのような作品です:

public override func viewDidLoad() { 
    super.viewDidLoad() 

    self.navigationController?.navigationBar.backgroundColor = UIColor.clear 
    self.navigationController?.navigationBar.isTranslucent = true 
    if #available(iOS 11.0, *) { 
     collectionView.contentInsetAdjustmentBehavior = .never 
    } else { 
     // Fallback on earlier versions 
    } 
} 

そしてもう一つ、私はそれが動作するためにはまだ必要であることが分かっていること。ほとんどの場合、あなたのUICollectionView/UITableView/UIScrollviewはセーフエリアの上部に揃えられています。代わりにこの制約をスーパービューの一番上に合わせて変更してください。

enter image description here

そして、それはそれです。それは直感的で直感的ではありませんか? Appleに感謝します。

関連する問題