Das Erstellen einer transparenten Navigationsleiste funktioniert nicht mehr mit ios 11 . Diese schwarze Leiste wird oben angezeigt, da die Tabellenansicht nicht mehr unter der Leiste angezeigt wird (die Einfügungen im Storyboard sind richtig auf 0 festgelegt). Irgendwelche Ideen warum?
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.isTranslucent = true
alt:
wenn Sie tableView verwendet haben, fügen Sie Code hinzu:
if (@available(iOS 11.0, *)) {
self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
} else {
self.automaticallyAdjustsScrollViewInsets = NO;
}
neu:
eine Änderung von automaticAdjustsScrollViewInsets 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));
es könnte sich um ein Problem von safeArea für iOS11 handeln.
#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)
Ich hatte das gleiche Problem und konnte es lösen. Folgendes funktioniert für mich:
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 eine Sache, die ich noch für nötig hielt, damit es funktioniert. Höchstwahrscheinlich haben Sie Ihre UICollectionView/UITableView/UIScrollview oben im sicheren Bereich ausgerichtet. Ändern Sie diese Einschränkung so, dass sie stattdessen am oberen Rand der Super-Ansicht ausgerichtet wird.
Und das ist es. Ist das nicht einfach und intuitiv? Danke, Apple.
Ich hatte ein ähnliches Problem. Ich habe "Extended Edges: Under Top/Bottom/Opaque Bar" für UIViewController im Storyboard auf "true" gesetzt . So. Sie können auch versuchen, " Automatische Anpassung der Bildlauf-Inserts " zu deaktivieren.
um ein konsistentes Verhalten zwischen iOS 10 und 11 zu erzielen, fügen Sie dieses zu Ihrem navigationViewController hinzu
func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
if navigationBar.isTranslucent, #available(iOS 11.0, *) {
viewController.additionalSafeAreaInsets.top = -navigationBar.bounds.height
}
}