Skip to content

Commit

Permalink
[Example] Fixed navigation bar problem in iOS15 (#1553)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfcon committed Nov 12, 2021
1 parent 1918f25 commit 016c191
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 66 deletions.
6 changes: 0 additions & 6 deletions MJRefreshExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
2D9BEB101BB15F4A00AED473 /* MJExample.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D9BEAF01BB15F4A00AED473 /* MJExample.m */; };
2D9BEB111BB15F4A00AED473 /* MJExampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D9BEAF21BB15F4A00AED473 /* MJExampleViewController.m */; };
2D9BEB121BB15F4A00AED473 /* MJExampleWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D9BEAF41BB15F4A00AED473 /* MJExampleWindow.m */; };
2D9BEB131BB15F4A00AED473 /* MJNavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D9BEAF61BB15F4A00AED473 /* MJNavigationController.m */; };
2D9BEB141BB15F4A00AED473 /* MJSingleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D9BEAF81BB15F4A00AED473 /* MJSingleViewController.m */; };
2D9BEB151BB15F4A00AED473 /* MJTempViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D9BEAFA1BB15F4A00AED473 /* MJTempViewController.m */; };
2D9BEB161BB15F4A00AED473 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D9BEAFD1BB15F4A00AED473 /* AppDelegate.m */; };
Expand Down Expand Up @@ -169,8 +168,6 @@
2D9BEAF21BB15F4A00AED473 /* MJExampleViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJExampleViewController.m; sourceTree = "<group>"; };
2D9BEAF31BB15F4A00AED473 /* MJExampleWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJExampleWindow.h; sourceTree = "<group>"; };
2D9BEAF41BB15F4A00AED473 /* MJExampleWindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJExampleWindow.m; sourceTree = "<group>"; };
2D9BEAF51BB15F4A00AED473 /* MJNavigationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJNavigationController.h; sourceTree = "<group>"; };
2D9BEAF61BB15F4A00AED473 /* MJNavigationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJNavigationController.m; sourceTree = "<group>"; };
2D9BEAF71BB15F4A00AED473 /* MJSingleViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJSingleViewController.h; sourceTree = "<group>"; };
2D9BEAF81BB15F4A00AED473 /* MJSingleViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJSingleViewController.m; sourceTree = "<group>"; };
2D9BEAF91BB15F4A00AED473 /* MJTempViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJTempViewController.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -328,8 +325,6 @@
2D9BEAF21BB15F4A00AED473 /* MJExampleViewController.m */,
2D9BEAF31BB15F4A00AED473 /* MJExampleWindow.h */,
2D9BEAF41BB15F4A00AED473 /* MJExampleWindow.m */,
2D9BEAF51BB15F4A00AED473 /* MJNavigationController.h */,
2D9BEAF61BB15F4A00AED473 /* MJNavigationController.m */,
2D9BEAF71BB15F4A00AED473 /* MJSingleViewController.h */,
2D9BEAF81BB15F4A00AED473 /* MJSingleViewController.m */,
2D9BEAF91BB15F4A00AED473 /* MJTempViewController.h */,
Expand Down Expand Up @@ -776,7 +771,6 @@
2D9BEB0A1BB15F4A00AED473 /* MJChiBaoZiFooter.m in Sources */,
2D9BEB121BB15F4A00AED473 /* MJExampleWindow.m in Sources */,
2DB2EA221BECBE6700D58F6A /* MJRefreshGifHeader.m in Sources */,
2D9BEB131BB15F4A00AED473 /* MJNavigationController.m in Sources */,
2DB2EA271BECBE6700D58F6A /* UIScrollView+MJExtension.m in Sources */,
2DB2EA1F1BECBE6700D58F6A /* MJRefreshBackGifFooter.m in Sources */,
0193FF132692E99500B52B11 /* I18NExampleViewController.swift in Sources */,
Expand Down
10 changes: 5 additions & 5 deletions MJRefreshExample/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19115.3" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="06B-cM-i4B">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19455" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="06B-cM-i4B">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19107.5"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19454"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand Down Expand Up @@ -84,7 +84,7 @@
<!--Navigation Controller-->
<scene sceneID="Gvt-ow-kGR">
<objects>
<navigationController storyboardIdentifier="0" id="06B-cM-i4B" customClass="MJNavigationController" sceneMemberID="viewController">
<navigationController storyboardIdentifier="0" id="06B-cM-i4B" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="Kj6-u7-ICR">
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
Expand All @@ -107,7 +107,7 @@
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<prototypes>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="example" textLabel="veW-N9-syp" detailTextLabel="Iv7-PA-lBt" style="IBUITableViewCellStyleSubtitle" id="xJS-7u-6pG">
<rect key="frame" x="0.0" y="50" width="375" height="44"/>
<rect key="frame" x="0.0" y="44.5" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="xJS-7u-6pG" id="rMg-IH-g5u">
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
Expand Down Expand Up @@ -186,4 +186,4 @@
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document>
</document>
13 changes: 0 additions & 13 deletions MJRefreshExample/Classes/First/MJNavigationController.h

This file was deleted.

25 changes: 0 additions & 25 deletions MJRefreshExample/Classes/First/MJNavigationController.m

This file was deleted.

40 changes: 23 additions & 17 deletions MJRefreshExample/Classes/Other/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,13 @@ @interface AppDelegate ()

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

[self setupNavigationBarAppearance];

return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
static dispatch_once_t onceToken;
Expand All @@ -42,8 +29,27 @@ - (void)applicationDidBecomeActive:(UIApplication *)application {
});
}

- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
- (void)setupNavigationBarAppearance {
// 1.取出设置主题的对象
UINavigationBar *navBar = [UINavigationBar appearanceWhenContainedInInstancesOfClasses:@[UINavigationController.class]];

// 2.设置导航栏的背景图片
UIImage *backgroundImage = [UIImage imageNamed:@"NavBar64"];
NSDictionary *titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]};

if (@available(iOS 13.0, *)) {
UINavigationBarAppearance *appearance = [UINavigationBarAppearance new];
appearance.backgroundImage = backgroundImage;
appearance.backgroundImageContentMode = UIViewContentModeScaleToFill;
appearance.titleTextAttributes = titleTextAttributes;

navBar.scrollEdgeAppearance = appearance;
navBar.standardAppearance = appearance;
} else {
[[UINavigationBar appearance] setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsDefault];
// 3.标题
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
}
}

@end

0 comments on commit 016c191

Please sign in to comment.