Skip to content

Commit

Permalink
iOS 14 support
Browse files Browse the repository at this point in the history
  • Loading branch information
MoZhouqi committed Sep 18, 2020
1 parent 5e37b54 commit 57e0c19
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 7 deletions.
2 changes: 1 addition & 1 deletion KMNavigationBarTransition.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "KMNavigationBarTransition"
s.version = "1.1.6"
s.version = "1.1.8"
s.summary = "A drop-in universal library makes transition animations smooth between different navigation bar styles while pushing or popping."

s.description = <<-DESC
Expand Down
7 changes: 5 additions & 2 deletions KMNavigationBarTransition.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand Down Expand Up @@ -418,6 +419,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand Down Expand Up @@ -458,6 +460,7 @@
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
Expand All @@ -472,7 +475,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.mo.KMNavigationBarTransition-Example";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -485,7 +488,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.mo.KMNavigationBarTransition-Example";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1200"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CDA3726E1C3907CE00E39A6D"
BuildableName = "KMNavigationBarTransition-Example.app"
BlueprintName = "KMNavigationBarTransition-Example"
ReferencedContainer = "container:KMNavigationBarTransition.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CDA3726E1C3907CE00E39A6D"
BuildableName = "KMNavigationBarTransition-Example.app"
BlueprintName = "KMNavigationBarTransition-Example"
ReferencedContainer = "container:KMNavigationBarTransition.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CDA3726E1C3907CE00E39A6D"
BuildableName = "KMNavigationBarTransition-Example.app"
BlueprintName = "KMNavigationBarTransition-Example"
ReferencedContainer = "container:KMNavigationBarTransition.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -51,8 +49,6 @@
ReferencedContainer = "container:KMNavigationBarTransition.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ - (void)km_addTransitionNavigationBarIfNeeded {
[self km_adjustScrollViewContentOffsetIfNeeded];
UINavigationBar *bar = [[UINavigationBar alloc] init];
bar.km_isFakeBar = YES;
if (@available(iOS 14, *)) {
bar.items = @[[UINavigationItem new]]; // fix Apple's bug in iOS 14
}
bar.barStyle = self.navigationController.navigationBar.barStyle;
if (bar.translucent != self.navigationController.navigationBar.translucent) {
bar.translucent = self.navigationController.navigationBar.translucent;
Expand Down

8 comments on commit 57e0c19

@Liaoworking
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

大兄弟这是什么奇淫思路 学习一下😂

@MoZhouqi
Copy link
Owner Author

@MoZhouqi MoZhouqi commented on 57e0c19 Sep 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

大兄弟这是什么奇淫思路 学习一下😂

主要是看了下 iOS 14 _isInnerNavigationBarOfNestedNavigationController 的实现,else 分支里是拿 _accessibility_navigationController._outermostNavigationController.navigationBar.topItemcustomNavigationBar.topItem 做比较,然后两个都是 nil,所以返回了 YES。结合这个方法的意图,我觉得问题出在没有判空。

@implementation _UINavigationBarVisualProviderModernIOS

- (BOOL)_isInnerNavigationBarOfNestedNavigationController {
    UINavigationBar *navigationBar = self.navigationBar; // custom navigation bar
    UINavigationController *accessibilityNavigationController = [navigationBar _accessibility_navigationController];
    UINavigationController *outermostNavigationController = [accessibilityNavigationController _outermostNavigationController];
    UINavigationBar *outermostNavigationBar = [outermostNavigationController navigationBar];
    if ([navigationBar == outermostNavigationBar]) {
        return NO;
    } else {
        return [navigationBar.topItem == outermostNavigationBar.topItem];
    }

}

@end

@Liaoworking
Copy link
Contributor

@Liaoworking Liaoworking commented on 57e0c19 Sep 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

大兄弟这是什么奇淫思路 学习一下😂

主要是看了下 iOS 14 _isInnerNavigationBarOfNestedNavigationController 的实现,else 分支里是拿 _accessibility_navigationController._outermostNavigationController.navigationBar.topItemcustomNavigationBar.topItem 做比较,然后两个都是 nil,所以返回了 YES。结合这个方法的意图,我觉得问题出在没有判空。

@implementation _UINavigationBarVisualProviderModernIOS

- (BOOL)_isInnerNavigationBarOfNestedNavigationController {
    UINavigationBar *navigationBar = self.navigationBar; // custom navigation bar
    UINavigationController *accessibilityNavigationController = [navigationBar _accessibility_navigationController];
    UINavigationController *outermostNavigationController = [accessibilityNavigationController _outermostNavigationController];
    UINavigationBar *outermostNavigationBar = [outermostNavigationController navigationBar];
    if ([navigationBar == outermostNavigationBar]) {
        return NO;
    } else {
        return [navigationBar.topItem == outermostNavigationBar.topItem];
    }

}

@end

大哥🐂🍺,
昨天和我的小伙伴讨论了很久这个问题的排查思路和根据你提供的方法去找线索,感觉有点收获,多向优秀的人学习自己才能变优秀哈哈😄。
感谢。

@MoZhouqi
Copy link
Owner Author

@MoZhouqi MoZhouqi commented on 57e0c19 Sep 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

大兄弟这是什么奇淫思路 学习一下😂

主要是看了下 iOS 14 _isInnerNavigationBarOfNestedNavigationController 的实现,else 分支里是拿 _accessibility_navigationController._outermostNavigationController.navigationBar.topItemcustomNavigationBar.topItem 做比较,然后两个都是 nil,所以返回了 YES。结合这个方法的意图,我觉得问题出在没有判空。

@implementation _UINavigationBarVisualProviderModernIOS

- (BOOL)_isInnerNavigationBarOfNestedNavigationController {
    UINavigationBar *navigationBar = self.navigationBar; // custom navigation bar
    UINavigationController *accessibilityNavigationController = [navigationBar _accessibility_navigationController];
    UINavigationController *outermostNavigationController = [accessibilityNavigationController _outermostNavigationController];
    UINavigationBar *outermostNavigationBar = [outermostNavigationController navigationBar];
    if ([navigationBar == outermostNavigationBar]) {
        return NO;
    } else {
        return [navigationBar.topItem == outermostNavigationBar.topItem];
    }

}

@end

大哥🐂🍺,
昨天和我的小伙伴讨论了很久这个问题的排查思路和根据你提供的方法去找线索,感觉有点收获,多向优秀的人学习自己才能变优秀哈哈😄。
感谢。

大佬过奖了,互相学习。🤝

@ZFBest
Copy link

@ZFBest ZFBest commented on 57e0c19 Sep 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
这段话意思是_accessibility_navigationController._outermostNavigationController.navigationBar.topItem 和 customNavigationBar.topItem 两个都是 nil,iOS14系统返回了NO。但其实两个都是 nil时也要返回YES的,对吗?

@MoZhouqi
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
这段话意思是_accessibility_navigationController._outermostNavigationController.navigationBar.topItem 和 customNavigationBar.topItem 两个都是 nil,iOS14系统返回了NO。但其实两个都是 nil时也要返回YES的,对吗?

iOS 14 在 navigation bar 布局的时候多了个判断 _isInnerNavigationBarOfNestedNavigationController,这个方法得返回 NO,这样 navigation bar 的 subviews 才会加载。
然后由于 _accessibility_navigationController._outermostNavigationController.navigationBar.topItemcustomNavigationBar.topItem 都是 nil,指针比较返回了 YES,最终导致自定义 navigation bar 的 subviews 没有被加载。
然后结合这个方法命名的含义,既然 accessibilityNavigationController 返回的是 nil,那这个方法就应该返回 NO 才对,所以我认为是苹果的 bug,没有判空。

@XiangWen
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

大兄弟这是什么奇淫思路 学习一下😂

主要是看了下 iOS 14 _isInnerNavigationBarOfNestedNavigationController 的实现,else 分支里是拿 _accessibility_navigationController._outermostNavigationController.navigationBar.topItemcustomNavigationBar.topItem 做比较,然后两个都是 nil,所以返回了 YES。结合这个方法的意图,我觉得问题出在没有判空。

@implementation _UINavigationBarVisualProviderModernIOS

- (BOOL)_isInnerNavigationBarOfNestedNavigationController {
    UINavigationBar *navigationBar = self.navigationBar; // custom navigation bar
    UINavigationController *accessibilityNavigationController = [navigationBar _accessibility_navigationController];
    UINavigationController *outermostNavigationController = [accessibilityNavigationController _outermostNavigationController];
    UINavigationBar *outermostNavigationBar = [outermostNavigationController navigationBar];
    if ([navigationBar == outermostNavigationBar]) {
        return NO;
    } else {
        return [navigationBar.topItem == outermostNavigationBar.topItem];
    }

}

@end

大哥🐂🍺,
昨天和我的小伙伴讨论了很久这个问题的排查思路和根据你提供的方法去找线索,感觉有点收获,多向优秀的人学习自己才能变优秀哈哈😄。
感谢。

大佬过奖了,互相学习。🤝

请问这个源码是在哪里能看到>_<

@MoZhouqi
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

大兄弟这是什么奇淫思路 学习一下😂

主要是看了下 iOS 14 _isInnerNavigationBarOfNestedNavigationController 的实现,else 分支里是拿 _accessibility_navigationController._outermostNavigationController.navigationBar.topItemcustomNavigationBar.topItem 做比较,然后两个都是 nil,所以返回了 YES。结合这个方法的意图,我觉得问题出在没有判空。

@implementation _UINavigationBarVisualProviderModernIOS

- (BOOL)_isInnerNavigationBarOfNestedNavigationController {
    UINavigationBar *navigationBar = self.navigationBar; // custom navigation bar
    UINavigationController *accessibilityNavigationController = [navigationBar _accessibility_navigationController];
    UINavigationController *outermostNavigationController = [accessibilityNavigationController _outermostNavigationController];
    UINavigationBar *outermostNavigationBar = [outermostNavigationController navigationBar];
    if ([navigationBar == outermostNavigationBar]) {
        return NO;
    } else {
        return [navigationBar.topItem == outermostNavigationBar.topItem];
    }

}

@end

大哥🐂🍺,
昨天和我的小伙伴讨论了很久这个问题的排查思路和根据你提供的方法去找线索,感觉有点收获,多向优秀的人学习自己才能变优秀哈哈😄。
感谢。

大佬过奖了,互相学习。🤝

请问这个源码是在哪里能看到>_<

逆向出来的。

Please sign in to comment.