2017-09-24 9 views
15

Das Erstellen einer transparenten Navigationsleiste funktioniert nicht mehr mit ios 11. Ich bekomme diese schwarze Leiste oben, weil die Tabellenansicht nicht mehr unter die Leiste kommt (die Inlays im Storyboard sind richtig eingestellt) von 0 anfangen) Irgendwelche Ideen warum?ios 11 transparente Navigationsleiste

enter image description here

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

Haben Sie versucht, self.navigationController? .navigationBar.backgroundColor = UIColor.clear auch hinzuzufügen? – Tom

+0

Ja, tat ich. Gleiches Ergebnis –

+0

Immer noch dasselbe Ergebnis –

Antwort

13

alt zu deaktivieren:

wenn Sie Tableview verwendet haben, fügen Sie den Code ein:

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

neu:

eine Änderung von automaticallyAdjustScr ollViewInsets in iOS11:

@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 

über contentInsetAdjustmentBehavior:

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)); 

könnte es ein Problem der safeArea für iOS11 sein. versuchen, diese von einem Experten definieren:

#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

hatte ich ein ähnliches Problem. Ich habe "Extended Edges: Under Top/Bottom/Opaque Bar" im Storyboard für UIViewController gesetzt. Like this. Sie können auch versuchen, "Automatically Adjusts Scroll View Insets"

+0

hatte ich schon unter oben und unten geprüft, aber nicht blickdicht. Durch die Überprüfung aller drei wurde das Problem behoben. –

4

konfrontiert ich das gleiche Problem, und ich war in der Lage, es zu lösen. Hier ist, was für mich funktioniert:

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 
    } 
} 

Und noch etwas, dass ich es arbeitet immer noch notwendig machen gefunden. Höchstwahrscheinlich haben Sie Ihre UICollectionView/UITableView/UIScrollview nach oben von Safe Area ausgerichtet. Ändern Sie diese Einschränkung so, dass sie stattdessen an der Spitze der Superansicht ausgerichtet wird.

enter image description here

Und das ist es. Ist es nicht einfach und intuitiv? Danke, Apple.

Verwandte Themen