iOS 11導(dǎo)航欄自定義UIBarButtonItem點(diǎn)擊區(qū)域變小
這里是為在xcode9 iOS 11之前我們是這樣寫的:
UIImage *image = [UIImage imageNamed:@"圖片名"];
UIImageView *backImageView = [[UIImageView alloc]initWithImage:image];
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:backImageView];
但是在xcode9 iOS 11必須設(shè)置frame,點(diǎn)擊區(qū)域才會變大
- 方法一 設(shè)置frame
UIImage *image = [UIImage imageNamed:@"圖片名"];
UIImageView *backImageView = [[UIImageView alloc]initWithImage:image];
backImageView.frame = CGRectMake(0, 0, 44, 44);
backImageView.contentMode = UIViewContentModeLeft;
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:backImageView];
- 方法二 參考stackoverflow
xcode9 iOS 11之后UINavigationBar現(xiàn)在是使用Auto Layout來來布局其子視圖,隨意我們應(yīng)該圖像添加寬度約束
- Swift添加約束
import UIKit
extension UIView {
func applyNavBarConstraints(size: (width: Float, height: Float)) {
let widthConstraint = self.widthAnchor.constraint(equalToConstant: width)
let heightConstraint = self.heightAnchor.constraint(equalToConstant: height)
heightConstraint.isActive = true
widthConstraint.isActive = true
}
}
// Usage
button.applyNavBarConstraints(size: (width: 33, height: 33))
- OC版添加約束
// UIView+Navbar.h
#import <UIKit/UIKit.h>
@interface UIView (Navbar)
- (void)applyNavBarConstraints:(CGFloat)width height:(CGFloat)height;
@end
//----------
// UIView+Navbar.m
#import "UIView+Navbar.h"
@implementation UIView (Navbar)
- (void)applyNavBarConstraints:(CGFloat)width height:(CGFloat)height
{
if (width == 0 || height == 0) {
return;
}
NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:height];
NSLayoutConstraint *widthConstraint = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:width];
[heightConstraint setActive:TRUE];
[widthConstraint setActive:TRUE];
}
//----------
// Usage :-
[button applyNavBarConstraints:33 height:33];
automaticallyAdjustsScrollViewInsets
automaticallyAdjustsScrollViewInsets
屬性被廢棄了炉旷,頂部就多了一定的inset
解決方法: 都可以寫成宏
- 必須在xcode9上運(yùn)行
if (@available(iOS 11.0, *)) {
scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}else{
controller.automaticallyAdjustsScrollViewInsets = NO;
}
2.可以在xcode9以下版本運(yùn)行
#define adjustsScrollViewInsets_NO(scrollView,controller) \
do { \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \
if ([UIScrollView instancesRespondToSelector:NSSelectorFromString(@"setContentInsetAdjustmentBehavior:")]) {\
[scrollView performSelector:NSSelectorFromString(@"setContentInsetAdjustmentBehavior:") withObject:@(2)];\
} else {\
controller.automaticallyAdjustsScrollViewInsets = NO;\
}\
_Pragma("clang diagnostic pop") \
} while (0)
tableview問題
- iOS 11中如果不實(shí)現(xiàn)
-tableView: viewForFooterInSection:
和-tableView: viewForHeaderInSection:
欢际,那么-tableView: heightForHeaderInSection:
和- tableView: heightForFooterInSection:
不會被調(diào)用
iOS 11修改tabbar的高度
iOS 11之前我們項(xiàng)目中是這樣修改tabBar的高度的;
//自定義TabBar高度
- (void) viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
CGRect tabFrame = self.tabBar.frame;
tabFrame.size.height = 60;
tabFrame.origin.y = self.view.frame.size.height - 60;
self.tabBar.frame = tabFrame;
self.tabBar.barStyle = UIBarStyleBlack;
}
升級iOS 11之后發(fā)現(xiàn)控制器跳轉(zhuǎn)的時候tabbar隱藏有問題,隱藏有延遲,往往是進(jìn)入了新控制器后tabbar延遲隱藏!一直以為是hidesBottomBarWhenPushed
設(shè)置時機(jī)的問題,糾結(jié)了一天.
在stackoverflow上看到一個關(guān)于Change UITabBar height的問題!里面有幾個關(guān)于XCode 9.0 iOS 11的解決方案!
-
嘗試方案一:
將viewWillLayoutSubviews
替換為viewDidLayoutSubviews
嘗試后 還是有問題
-
嘗試方案二: 重寫tabbar的sizeThatFits
這個方案是可以的
@property(nonatomic,readonly) UITabBar *tabBar
是 readonly
的! 我們可以通過KVC
設(shè)置
[self setValue:自定義tabbar forKey:@"tabBar"];
iOS 11 WKWebView崩潰
崩潰信息:通過全局?jǐn)帱c(diǎn)崩潰在下面
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
中的decisionHandler
解決方案: 保證了單次LoadRequest只執(zhí)行一次decisionHandler()
- (void)webView:(WKWebView *)webView
decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction
decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
if (webView != _webView) { return; }
NSURL *url = navigationAction.request.URL;
__strong typeof(_webViewDelegate) strongDelegate = _webViewDelegate;
if ([_base isCorrectProcotocolScheme:url]) {
if ([_base isBridgeLoadedURL:url]) {
[_base injectJavascriptFile];
} else if ([_base isQueueMessageURL:url]) {
[self WKFlushMessageQueue];
} else {
[_base logUnkownMessage:url];
}
**decisionHandler(WKNavigationActionPolicyCancel); // executed**
}
if (strongDelegate && [strongDelegate respondsToSelector:@selector(webView:decidePolicyForNavigationAction:decisionHandler:)]) {
**[_webViewDelegate webView:webView decidePolicyForNavigationAction:navigationAction decisionHandler:decisionHandler]; // executed**
} else {
decisionHandler(WKNavigationActionPolicyAllow);
}
}
或者在合適的地方return
,避免重復(fù)調(diào)用decisionHandler
參考
參考
https://github.com/marcuswestin/WebViewJavascriptBridge/issues/278
iOS11 Xcode9 WKWebView崩潰問題解決方案
Marketing Icon
Missing Marketing Icon. iOS Apps must include a 1024x1024px Marketing Icon in PNG format. Apps that do not include the Marketing Icon cannot be submitted for App Review or Beta App Review.
9月份上傳的時候,沒有1024*1024的營銷圖標(biāo)只是有警告,現(xiàn)在上傳的時候也是有警告的,但是提交審核的時候直接不能提交審核!
解決iOS11刷新tableview會出現(xiàn)漂移的現(xiàn)象
_tableView.estimatedRowHeight = 0;
_tableView.estimatedSectionHeaderHeight = 0;
_tableView.estimatedSectionFooterHeight = 0;