10 |
11 | @interface YPDemoSwitchCell : UITableViewCell
12 |
13 | @property (nonatomic, strong, readonly) UISwitch *switcher;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/Examples/share/cells/YPDemoSwitchCell.m:
--------------------------------------------------------------------------------
1 | //
2 | // YPDemoSwitchCell.m
3 | // YPNavigationBarTransition-Example
4 | //
5 | // Created by Guoyin Lee on 26/12/2017.
6 | // Copyright © 2017 yiplee. All rights reserved.
7 | //
8 |
9 | #import "YPDemoSwitchCell.h"
10 |
11 | @implementation YPDemoSwitchCell
12 |
13 | - (instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
14 | self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
15 | if (self) {
16 | self.selectionStyle = UITableViewCellSelectionStyleNone;
17 | self.accessoryType = UITableViewCellAccessoryNone;
18 |
19 | _switcher = [UISwitch new];
20 | self.accessoryView = _switcher;
21 | }
22 |
23 | return self;
24 | }
25 |
26 | - (void) prepareForReuse {
27 | [super prepareForReuse];
28 |
29 | _switcher.on = NO;
30 | [_switcher removeTarget:nil
31 | action:nil
32 | forControlEvents:UIControlEventValueChanged];
33 | }
34 |
35 | @end
36 |
--------------------------------------------------------------------------------
/Examples/share/lakeside_sunset.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yiplee/YPNavigationBarTransition/7543ff1ef819003bef06d8a0f7c1e93e2b2b3fbe/Examples/share/lakeside_sunset.png
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source 'https://rubygems.org'
2 |
3 | gem 'cocoapods', '1.5.3'
4 | gem 'slather', '~> 2.4.0'
5 | gem 'xcpretty', '0.2.4'
--------------------------------------------------------------------------------
/Gemfile.lock:
--------------------------------------------------------------------------------
1 | GEM
2 | remote: https://rubygems.org/
3 | specs:
4 | CFPropertyList (2.3.6)
5 | activesupport (4.2.10)
6 | i18n (~> 0.7)
7 | minitest (~> 5.1)
8 | thread_safe (~> 0.3, >= 0.3.4)
9 | tzinfo (~> 1.1)
10 | atomos (0.1.3)
11 | claide (1.0.2)
12 | clamp (0.6.5)
13 | cocoapods (1.5.3)
14 | activesupport (>= 4.0.2, < 5)
15 | claide (>= 1.0.2, < 2.0)
16 | cocoapods-core (= 1.5.3)
17 | cocoapods-deintegrate (>= 1.0.2, < 2.0)
18 | cocoapods-downloader (>= 1.2.0, < 2.0)
19 | cocoapods-plugins (>= 1.0.0, < 2.0)
20 | cocoapods-search (>= 1.0.0, < 2.0)
21 | cocoapods-stats (>= 1.0.0, < 2.0)
22 | cocoapods-trunk (>= 1.3.0, < 2.0)
23 | cocoapods-try (>= 1.1.0, < 2.0)
24 | colored2 (~> 3.1)
25 | escape (~> 0.0.4)
26 | fourflusher (~> 2.0.1)
27 | gh_inspector (~> 1.0)
28 | molinillo (~> 0.6.5)
29 | nap (~> 1.0)
30 | ruby-macho (~> 1.1)
31 | xcodeproj (>= 1.5.7, < 2.0)
32 | cocoapods-core (1.5.3)
33 | activesupport (>= 4.0.2, < 6)
34 | fuzzy_match (~> 2.0.4)
35 | nap (~> 1.0)
36 | cocoapods-deintegrate (1.0.2)
37 | cocoapods-downloader (1.6.3)
38 | cocoapods-plugins (1.0.0)
39 | nap
40 | cocoapods-search (1.0.0)
41 | cocoapods-stats (1.0.0)
42 | cocoapods-trunk (1.3.1)
43 | nap (>= 0.8, < 2.0)
44 | netrc (~> 0.11)
45 | cocoapods-try (1.1.0)
46 | colored2 (3.1.2)
47 | concurrent-ruby (1.0.5)
48 | escape (0.0.4)
49 | fourflusher (2.0.1)
50 | fuzzy_match (2.0.4)
51 | gh_inspector (1.1.3)
52 | i18n (0.9.5)
53 | concurrent-ruby (~> 1.0)
54 | mini_portile2 (2.3.0)
55 | minitest (5.11.3)
56 | molinillo (0.6.6)
57 | nanaimo (0.2.6)
58 | nap (1.1.0)
59 | netrc (0.11.0)
60 | nokogiri (1.8.5)
61 | mini_portile2 (~> 2.3.0)
62 | rouge (1.11.1)
63 | ruby-macho (1.2.0)
64 | slather (2.4.6)
65 | CFPropertyList (~> 2.2)
66 | activesupport (>= 4.0.2)
67 | clamp (~> 0.6)
68 | nokogiri (~> 1.8.2)
69 | xcodeproj (~> 1.4)
70 | thread_safe (0.3.6)
71 | tzinfo (1.2.5)
72 | thread_safe (~> 0.1)
73 | xcodeproj (1.6.0)
74 | CFPropertyList (>= 2.3.3, < 4.0)
75 | atomos (~> 0.1.3)
76 | claide (>= 1.0.2, < 2.0)
77 | colored2 (~> 3.1)
78 | nanaimo (~> 0.2.6)
79 | xcpretty (0.2.4)
80 | rouge (~> 1.8)
81 |
82 | PLATFORMS
83 | ruby
84 |
85 | DEPENDENCIES
86 | cocoapods (= 1.5.3)
87 | slather (~> 2.4.0)
88 | xcpretty (= 0.2.4)
89 |
90 | BUNDLED WITH
91 | 1.16.2
92 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 yiplee
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Podfile:
--------------------------------------------------------------------------------
1 | # Uncomment the next line to define a global platform for your project
2 | platform :ios, '8.0'
3 | use_frameworks!
4 |
5 | target 'YPNavigationBarTransitionTests' do
6 | pod 'Kiwi', :inhibit_warnings => true
7 | end
8 |
9 |
--------------------------------------------------------------------------------
/Podfile.lock:
--------------------------------------------------------------------------------
1 | PODS:
2 | - Kiwi (2.4.0)
3 |
4 | DEPENDENCIES:
5 | - Kiwi
6 |
7 | SPEC REPOS:
8 | https://github.com/cocoapods/specs.git:
9 | - Kiwi
10 |
11 | SPEC CHECKSUMS:
12 | Kiwi: f49c9d54b28917df5928fe44968a39ed198cb8a8
13 |
14 | PODFILE CHECKSUM: cc67ff09cb9339e0ee42d87c7af45db04b395224
15 |
16 | COCOAPODS: 1.6.1
17 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # YPNavigationBarTransition
2 |
3 |
4 |
5 |
7 |
8 |
9 |
11 |
12 |
15 |
16 |
18 |
19 |
20 |
21 | A Fully functional `UINavigationBar` framework for making bar transition more natural! You don't need to call any `UINavigationBar` api, implementing `YPNavigationBarConfigureStyle` protocol for your view controller instead.
22 |
23 | 类似微信 UINavigationBar 效果的切换方案,支持任意透明半透明图片背景等等不同样式的 UINavigationBar 的切换。
24 |
25 | ## features
26 |
27 | - Transparent & translucent navigation bar 支持不透明、全透明和半透明的 navigation bar
28 | - Pure color bar 支持设置 navigation bar 背景颜色
29 | - Background image bar 支持设置 navigation bar 背景图片
30 | - Update navigationBar style **dynamicly** 可以动态调整 navigation bar 样式
31 | - Written in Objective-C with full Swift interop support
32 |
33 | ### 不同颜色和透明度的 bar 之间的切换
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 | ### 图片背景的 navigation bar
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | ### 动态调整 navigation bar 样式
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 | ## Requirements
58 |
59 | - Xcode 9.0+
60 | - iOS 8.0+
61 |
62 | ## Installation
63 |
64 | ### CocoaPods
65 |
66 | The preferred installation method is with [CocoaPods](https://cocoapods.org). Add the following to your `Podfile`:
67 |
68 | ```ruby
69 | # use_frameworks! is needed for swift projects
70 | use_frameworks!
71 | pod 'YPNavigationBarTransition', '~> 2.0'
72 | ```
73 |
74 | ### Carthage
75 |
76 | For [Carthage](https://github.com/Carthage/Carthage), add the following to your `Cartfile`:
77 |
78 | ```ruby
79 | github "yiplee/YPNavigationBarTransition" ~> 2.0
80 | ```
81 |
82 | ## Getting Started
83 |
84 | ### 1. Import Framework
85 |
86 | ```objc
87 | // objc
88 | #import
89 | ```
90 |
91 | ```swift
92 | // swift
93 | import YPNavigationBarTransition
94 | ```
95 |
96 | ### 2. Replace UINavigationController with YPNavigationController
97 |
98 | ### 3. Implement Protocol YPNavigationBarConfigureStyle for YPNavigationController in Category
99 |
100 | ```objc
101 | // objc (this will be your app's default navigationbar style)
102 | @implementation YPNavigationController (Configure)
103 |
104 | - (YPNavigationBarConfigurations) yp_navigtionBarConfiguration {
105 | return YPNavigationBarStyleBlack | YPNavigationBarBackgroundStyleTranslucent | YPNavigationBarBackgroundStyleNone;
106 | }
107 |
108 | - (UIColor *) yp_navigationBarTintColor {
109 | return [UIColor whiteColor];
110 | }
111 | ```
112 |
113 | ```swift
114 | // swift (this will be your app's default navigationbar style)
115 | extension YPNavigationController : NavigationBarConfigureStyle {
116 | public func yp_navigtionBarConfiguration() -> YPNavigationBarConfigurations {
117 | return [.styleBlack]
118 | }
119 |
120 | public func yp_navigationBarTintColor() -> UIColor! {
121 | return UIColor.white
122 | }
123 | }
124 | ```
125 |
126 | - [example projects](https://github.com/yiplee/YPNavigationBarTransition/tree/master/Examples)
127 | - [How To Use 中文](https://github.com/yiplee/YPNavigationBarTransition/blob/master/docs/how_to_use_CN.markdown)
128 |
129 | ## License
130 |
131 | MIT. See the [LICENSE](LICENSE) file for details.
132 |
133 |
--------------------------------------------------------------------------------
/YPNavigationBarTransition.podspec:
--------------------------------------------------------------------------------
1 | Pod::Spec.new do |s|
2 |
3 |
4 | s.name = "YPNavigationBarTransition"
5 | s.version = "2.2.2"
6 | s.summary = "A Fully functional UINavigationBar framework for making bar transition more natural!"
7 | s.description = "A Fully functional UINavigationBar framework for making bar transition more natural! You don't need to call any UINavigationBar api, implementing YPNavigationBarConfigureStyle protocol for your view controller instead."
8 |
9 | s.homepage = "http://github.com/yiplee/YPNavigationBarTransition"
10 | s.screenshots = "https://raw.githubusercontent.com/yiplee/YPNavigationBarTransition/master/screenshots/gif-01.gif", "https://raw.githubusercontent.com/yiplee/YPNavigationBarTransition/master/screenshots/gif-02.gif"
11 |
12 | s.license = { :type => "MIT", :file => "LICENSE" }
13 |
14 | s.author = { "yiplee" => "guoyinl@gmail.com" }
15 | s.social_media_url = "https://twitter.com/yipleeyin"
16 |
17 | # s.platform = :ios
18 | s.platform = :ios, "8.0"
19 |
20 | # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
21 | #
22 | # Specify the location from where the source should be retrieved.
23 | # Supports git, hg, bzr, svn and HTTP.
24 | #
25 |
26 | s.source = { :git => "https://github.com/yiplee/YPNavigationBarTransition.git", :tag => s.version.to_s}
27 |
28 | s.source_files = "YPNavigationBarTransition/**/*.{h,m}"
29 | s.public_header_files = 'YPNavigationBarTransition/*.h'
30 | s.private_header_files = "YPNavigationBarTransition/internal/*.h"
31 |
32 | s.frameworks = "UIKit" ,"Foundation"
33 | s.requires_arc = true
34 |
35 | end
36 |
--------------------------------------------------------------------------------
/YPNavigationBarTransition.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/YPNavigationBarTransition.xcodeproj/xcshareddata/xcschemes/YPNavigationBarTransitionLibrary.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
31 |
32 |
34 |
40 |
41 |
42 |
43 |
44 |
50 |
51 |
52 |
53 |
54 |
55 |
65 |
66 |
72 |
73 |
74 |
75 |
76 |
77 |
83 |
84 |
90 |
91 |
92 |
93 |
95 |
96 |
99 |
100 |
101 |
--------------------------------------------------------------------------------
/YPNavigationBarTransition.xcodeproj/xcshareddata/xcschemes/YPNavigationBarTransitionTests.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
16 |
18 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
40 |
41 |
42 |
43 |
49 |
50 |
52 |
53 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/YPNavigationBarTransition.xcodeproj/xcuserdata/yiplee.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/YPNavigationBarTransition.xcodeproj/xcuserdata/yiplee.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | YPNavigationBarTransitionLibrary.xcscheme_^#shared#^_
8 |
9 | orderHint
10 | 0
11 |
12 | YPNavigationBarTransitionTests.xcscheme_^#shared#^_
13 |
14 | orderHint
15 | 2
16 |
17 |
18 | SuppressBuildableAutocreation
19 |
20 | E8B064221FEF4FBC007332E8
21 |
22 | primary
23 |
24 |
25 | E8B0642B1FEF4FBC007332E8
26 |
27 | primary
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/YPNavigationBarTransition.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/YPNavigationBarTransition.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/YPNavigationBarTransition/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | FMWK
17 | CFBundleShortVersionString
18 | 2.0.9
19 | CFBundleVersion
20 | $(CURRENT_PROJECT_VERSION)
21 | NSPrincipalClass
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/YPNavigationBarTransition/UIImage+YPConfigure.h:
--------------------------------------------------------------------------------
1 | /*
2 | MIT License
3 |
4 | Copyright (c) 2017 yiplee
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | #import
26 |
27 | @interface UIImage (YPConfigure)
28 |
29 | + (UIImage *) yp_transparentImage;
30 |
31 | + (UIImage *) yp_imageWithColor:(UIColor *)color;
32 | + (UIImage *) yp_imageWithColor:(UIColor *)color size:(CGSize) size;
33 |
34 | @end
35 |
--------------------------------------------------------------------------------
/YPNavigationBarTransition/UIImage+YPConfigure.m:
--------------------------------------------------------------------------------
1 | /*
2 | MIT License
3 |
4 | Copyright (c) 2017 yiplee
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | #import "UIImage+YPConfigure.h"
26 |
27 | @implementation UIImage (YPConfigure)
28 |
29 | + (UIImage *) yp_transparentImage {
30 | return [self new];
31 | }
32 |
33 | + (UIImage *) yp_imageWithColor:(UIColor *)color {
34 | return [self yp_imageWithColor:color size:CGSizeMake(1, 1)];
35 | }
36 |
37 | + (UIImage *) yp_imageWithColor:(UIColor *)color size:(CGSize) size {
38 | size.width = MAX(0.5, size.width);
39 | size.height = MAX(0.5, size.height);
40 |
41 | CGRect rect = CGRectMake(0.0f, 0.0f, size.width, size.height);
42 | UIGraphicsBeginImageContext(rect.size);
43 | CGContextRef context = UIGraphicsGetCurrentContext();
44 |
45 | CGContextSetFillColorWithColor(context, [color CGColor]);
46 | CGContextFillRect(context, rect);
47 |
48 | UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
49 | UIGraphicsEndImageContext();
50 |
51 | return image;
52 | }
53 |
54 | @end
55 |
--------------------------------------------------------------------------------
/YPNavigationBarTransition/UIViewController+YPNavigationBarTransition.h:
--------------------------------------------------------------------------------
1 | /*
2 | MIT License
3 |
4 | Copyright (c) 2017 yiplee
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | #import
26 |
27 | @interface UIViewController (YPNavigationBarTransition)
28 |
29 | - (BOOL) yp_hasCustomNavigationBarStyle;
30 |
31 | - (void) yp_refreshNavigationBarStyle;
32 |
33 | - (CGRect) yp_fakeBarFrameForNavigationBar:(UINavigationBar *)navigationBar;
34 |
35 | @end
36 |
--------------------------------------------------------------------------------
/YPNavigationBarTransition/UIViewController+YPNavigationBarTransition.m:
--------------------------------------------------------------------------------
1 | /*
2 | MIT License
3 |
4 | Copyright (c) 2017 yiplee
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | #import "UIViewController+YPNavigationBarTransition.h"
26 | #import "YPBarConfiguration.h"
27 | #import "UINavigationBar+YPConfigure.h"
28 |
29 | @implementation UIViewController (YPNavigationBarTransition)
30 |
31 | - (BOOL) yp_hasCustomNavigationBarStyle {
32 | return [self conformsToProtocol:@protocol(YPNavigationBarConfigureStyle)];
33 | }
34 |
35 | - (UINavigationBar *) yp_navigationBar {
36 | if ([self isKindOfClass:[UINavigationController class]]) {
37 | return [(UINavigationController*)self navigationBar];
38 | }
39 |
40 | return [self.navigationController navigationBar];
41 | }
42 |
43 | - (void) yp_refreshNavigationBarStyle {
44 | NSParameterAssert([self yp_hasCustomNavigationBarStyle]);
45 |
46 | UINavigationBar *navigationBar = [self yp_navigationBar];
47 | if (navigationBar.topItem == self.navigationItem) {
48 | id owner = (id)self;
49 | YPBarConfiguration *configuration = [[YPBarConfiguration alloc] initWithBarConfigurationOwner:owner];
50 | [navigationBar yp_applyBarConfiguration:configuration];
51 | }
52 | }
53 |
54 | - (CGRect) yp_fakeBarFrameForNavigationBar:(UINavigationBar *)navigationBar {
55 | if (!navigationBar) return CGRectNull;
56 |
57 | UIView *backgroundView = [navigationBar yp_backgroundView];
58 | CGRect frame = [backgroundView.superview convertRect:backgroundView.frame toView:self.view];
59 | frame.origin.x = self.view.bounds.origin.x;
60 | return frame;
61 | }
62 |
63 | @end
64 |
--------------------------------------------------------------------------------
/YPNavigationBarTransition/YPNavigationBarProtocol.h:
--------------------------------------------------------------------------------
1 | /*
2 | MIT License
3 |
4 | Copyright (c) 2017 yiplee
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | #import
26 | #import
27 |
28 | NS_SWIFT_NAME(NavigationBarConfigurations)
29 | typedef NS_OPTIONS(NSUInteger, YPNavigationBarConfigurations) {
30 | YPNavigationBarShow = 0, // show navigationBar
31 | YPNavigationBarHidden = 1, // hide navigationBar
32 |
33 | // bar style
34 | YPNavigationBarStyleLight = 0 << 4, // UIbarStyleDefault
35 | YPNavigationBarStyleBlack = 1 << 4, // UIbarStyleBlack
36 |
37 | YPNavigationBarBackgroundStyleTranslucent = 0 << 8,
38 | YPNavigationBarBackgroundStyleOpaque = 1 << 8,
39 | YPNavigationBarBackgroundStyleTransparent = 2 << 8,
40 |
41 | // bar background
42 | YPNavigationBarBackgroundStyleNone = 0 << 16,
43 | YPNavigationBarBackgroundStyleColor = 1 << 16,
44 | YPNavigationBarBackgroundStyleImage = 2 << 16,
45 |
46 | // shadow image
47 | YPNavigationBarShowShadowImage = 1 << 20,
48 |
49 | YPNavigationBarConfigurationsDefault = 0,
50 | };
51 |
52 | NS_SWIFT_NAME(NavigationBarConfigureStyle)
53 | @protocol YPNavigationBarConfigureStyle
54 |
55 | - (YPNavigationBarConfigurations) yp_navigtionBarConfiguration;
56 |
57 | - (UIColor *) yp_navigationBarTintColor;
58 |
59 | @optional
60 |
61 | /*
62 | * identifier 用来比较image的name是否是同,如果不传,会使用image的isEqual来比较
63 | */
64 | - (UIImage *) yp_navigationBackgroundImageWithIdentifier:(NSString **)identifier;
65 |
66 | - (UIColor *) yp_navigationBackgroundColor;
67 |
68 | @end
69 |
--------------------------------------------------------------------------------
/YPNavigationBarTransition/YPNavigationBarTransition.h:
--------------------------------------------------------------------------------
1 | /*
2 | MIT License
3 |
4 | Copyright (c) 2017 yiplee
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | #import
26 |
27 | //! Project version number for YPNavigationBarTransition.
28 | FOUNDATION_EXPORT double YPNavigationBarTransitionVersionNumber;
29 |
30 | //! Project version string for YPNavigationBarTransition.
31 | FOUNDATION_EXPORT const unsigned char YPNavigationBarTransitionVersionString[];
32 | //
33 | #import
34 | #import
35 | #import
36 | #import
37 | #import
38 |
39 |
40 |
--------------------------------------------------------------------------------
/YPNavigationBarTransition/YPNavigationBarTransitionCenter.h:
--------------------------------------------------------------------------------
1 | /*
2 | MIT License
3 |
4 | Copyright (c) 2017 yiplee
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | #import
26 |
27 | NS_ASSUME_NONNULL_BEGIN
28 |
29 | NS_SWIFT_NAME(NavigationBarTransitionCenter)
30 | @interface YPNavigationBarTransitionCenter : NSObject
31 |
32 | @property (nonatomic, assign) BOOL isTransitionNavigationBar;
33 |
34 | - (instancetype) init NS_UNAVAILABLE;
35 | + (instancetype) new NS_UNAVAILABLE;
36 | - (instancetype) initWithDefaultBarConfiguration:(id)_default NS_DESIGNATED_INITIALIZER;
37 |
38 | - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
39 | - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
40 |
41 | @end
42 |
43 | NS_ASSUME_NONNULL_END
44 |
--------------------------------------------------------------------------------
/YPNavigationBarTransition/YPNavigationController.h:
--------------------------------------------------------------------------------
1 | //
2 | // YPNavigationController.h
3 | // YPNavigationBarTransition-Example
4 | //
5 | // Created by Guoyin Lee on 2018/4/20.
6 | // Copyright © 2018 yiplee. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface YPNavigationController : UINavigationController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/YPNavigationBarTransition/YPNavigationController.m:
--------------------------------------------------------------------------------
1 | //
2 | // YPNavigationController.m
3 | // YPNavigationBarTransition-Example
4 | //
5 | // Created by Guoyin Lee on 2018/4/20.
6 | // Copyright © 2018 yiplee. All rights reserved.
7 | //
8 |
9 | #import "YPNavigationController.h"
10 | #import "YPNavigationControllerDelegateProxy.h"
11 | #import "YPNavigationBarTransitionCenter.h"
12 | #import "YPNavigationBarProtocol.h"
13 |
14 | @interface YPNavigationController ()
15 | <
16 | UIGestureRecognizerDelegate,
17 | UINavigationControllerDelegate
18 | >
19 |
20 | @property (nonatomic, strong) YPNavigationBarTransitionCenter *center;
21 | @property (nonatomic, weak, nullable) id navigationDelegate;
22 | @property (nonatomic, strong, nullable) YPNavigationControllerDelegateProxy *delegateProxy;
23 |
24 | @end
25 |
26 | @implementation YPNavigationController
27 |
28 | - (void)viewDidLoad {
29 | [super viewDidLoad];
30 |
31 | // see YPNavigationController+Configure.{h,m} in Example Project
32 | NSAssert([self conformsToProtocol:@protocol(YPNavigationBarConfigureStyle)],
33 | @"you must implement YPNavigationBarConfigureStyle for YPNavigationController in subclass or category");
34 |
35 | _center = [[YPNavigationBarTransitionCenter alloc] initWithDefaultBarConfiguration:(id)self];
36 | if (!self.delegate) {
37 | self.delegate = self;
38 | }
39 | self.interactivePopGestureRecognizer.delegate = self;
40 | }
41 |
42 | - (void) setDelegate:(id)delegate {
43 | if (delegate == self || delegate == nil) {
44 | _navigationDelegate = nil;
45 | _delegateProxy = nil;
46 | super.delegate = self;
47 | } else {
48 | _navigationDelegate = delegate;
49 | _delegateProxy = [[YPNavigationControllerDelegateProxy alloc] initWithNavigationTarget:_navigationDelegate
50 | interceptor:self];
51 | super.delegate = (id)_delegateProxy;
52 | }
53 | }
54 |
55 | #pragma mark - UINavigationControllerDelegate
56 |
57 | - (void) navigationController:(UINavigationController *)navigationController
58 | willShowViewController:(UIViewController *)viewController
59 | animated:(BOOL)animated {
60 | id navigationDelegate = self.navigationDelegate;
61 | if ([navigationDelegate respondsToSelector:@selector(navigationController:willShowViewController:animated:)]) {
62 | [navigationDelegate navigationController:navigationController
63 | willShowViewController:viewController
64 | animated:animated];
65 | }
66 |
67 | [_center navigationController:navigationController
68 | willShowViewController:viewController
69 | animated:animated];
70 | }
71 |
72 | - (void) navigationController:(UINavigationController *)navigationController
73 | didShowViewController:(UIViewController *)viewController
74 | animated:(BOOL)animated {
75 | id navigationDelegate = self.navigationDelegate;
76 | if ([navigationDelegate respondsToSelector:@selector(navigationController:didShowViewController:animated:)]) {
77 | [navigationDelegate navigationController:navigationController
78 | didShowViewController:viewController
79 | animated:animated];
80 | }
81 |
82 | [_center navigationController:navigationController
83 | didShowViewController:viewController
84 | animated:animated];
85 | }
86 |
87 | #pragma mark - UIGestureRecognizerDelegate
88 |
89 | - (BOOL) gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
90 | if (gestureRecognizer == self.interactivePopGestureRecognizer) {
91 | if ([gestureRecognizer isKindOfClass:UIScreenEdgePanGestureRecognizer.class] && _center.isTransitionNavigationBar) {
92 | return NO;
93 | }
94 | return self.viewControllers.count > 1;
95 | }
96 |
97 | return YES;
98 | }
99 |
100 | @end
101 |
--------------------------------------------------------------------------------
/YPNavigationBarTransition/internal/UINavigationBar+YPConfigure.h:
--------------------------------------------------------------------------------
1 | /*
2 | MIT License
3 |
4 | Copyright (c) 2017 yiplee
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | #import
26 |
27 | @class YPBarConfiguration;
28 |
29 | @interface UINavigationBar (YPConfigure)
30 |
31 | @property (nonatomic, strong, readonly) YPBarConfiguration* currentBarConfigure;
32 |
33 | - (void) yp_adjustWithBarStyle:(UIBarStyle)barStyle tintColor:(UIColor *)tintColor;
34 | - (void) yp_applyBarConfiguration:(YPBarConfiguration *)configure;
35 |
36 | - (UIView *) yp_backgroundView;
37 |
38 | @end
39 |
--------------------------------------------------------------------------------
/YPNavigationBarTransition/internal/UINavigationBar+YPConfigure.m:
--------------------------------------------------------------------------------
1 | /*
2 | MIT License
3 |
4 | Copyright (c) 2017 yiplee
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 | #import "UINavigationBar+YPConfigure.h"
25 | #import "YPBarConfiguration.h"
26 | #import "UIImage+YPConfigure.h"
27 | #import
28 |
29 | @implementation UINavigationBar (YPConfigure)
30 |
31 | - (void) yp_adjustWithBarStyle:(UIBarStyle)barStyle tintColor:(UIColor *)tintColor {
32 | self.barStyle = barStyle;
33 | self.tintColor = tintColor;
34 | }
35 |
36 | - (UIView *) yp_backgroundView {
37 | return [self valueForKey:@"_backgroundView"];
38 | }
39 |
40 | - (void) yp_applyBarConfiguration:(YPBarConfiguration *)configure {
41 | #if DEBUG
42 | if (@available(iOS 11,*)) {
43 | NSAssert(!self.prefersLargeTitles, @"large titles is not supported");
44 | }
45 | #endif
46 |
47 | [self yp_adjustWithBarStyle:configure.barStyle tintColor:configure.tintColor];
48 |
49 | UIView *barBackgroundView = [self yp_backgroundView];
50 | UIImage* const transpanrentImage = [UIImage yp_transparentImage];
51 | if (configure.transparent) {
52 | barBackgroundView.alpha = 0;
53 | if (@available(iOS 13.0, *)) {
54 | UINavigationBarAppearance *appearance = [[self standardAppearance] copy];
55 | [appearance configureWithTransparentBackground];
56 | self.scrollEdgeAppearance = appearance;
57 | self.standardAppearance = appearance;
58 | } else {
59 | self.translucent = YES;
60 | [self setBackgroundImage:transpanrentImage forBarMetrics:UIBarMetricsDefault];
61 | }
62 | } else {
63 | barBackgroundView.alpha = 1;
64 | if (@available(iOS 13.0, *)) {
65 | UINavigationBarAppearance *appearance = [[self standardAppearance] copy];
66 | if (configure.translucent) {
67 | [appearance configureWithDefaultBackground];
68 | UIBlurEffectStyle effectStyle = configure.barStyle == UIBarStyleDefault ? UIBlurEffectStyleLight : UIBlurEffectStyleDark;
69 | appearance.backgroundEffect = [UIBlurEffect effectWithStyle:effectStyle];
70 | } else {
71 | [appearance configureWithOpaqueBackground];
72 | }
73 | if (configure.backgroundImage) {
74 | appearance.backgroundImage = configure.backgroundImage;
75 | } else if (configure.backgroundColor) {
76 | appearance.backgroundColor = configure.backgroundColor;
77 | }
78 | if (!configure.shadowImage) {
79 | appearance.shadowImage = nil;
80 | appearance.shadowColor = nil;
81 | }
82 | self.scrollEdgeAppearance = appearance;
83 | self.standardAppearance = appearance;
84 | } else {
85 | self.translucent = configure.translucent;
86 | UIImage* backgroundImage = configure.backgroundImage;
87 | if (!backgroundImage && configure.backgroundColor) {
88 | backgroundImage = [UIImage yp_imageWithColor:configure.backgroundColor];
89 | }
90 | [self setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsDefault];
91 | }
92 | }
93 |
94 | self.shadowImage = configure.shadowImage ? nil : transpanrentImage;
95 |
96 | [self setCurrentBarConfigure:configure];
97 | }
98 |
99 | - (YPBarConfiguration *) currentBarConfigure {
100 | return objc_getAssociatedObject(self, @selector(currentBarConfigure));
101 | }
102 |
103 | - (void) setCurrentBarConfigure:(YPBarConfiguration *)currentBarConfigure {
104 | objc_setAssociatedObject(self, @selector(currentBarConfigure), currentBarConfigure, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
105 | }
106 |
107 | @end
108 |
--------------------------------------------------------------------------------
/YPNavigationBarTransition/internal/UIToolbar+YPConfigure.h:
--------------------------------------------------------------------------------
1 | /*
2 | MIT License
3 |
4 | Copyright (c) 2017 yiplee
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | #import
26 |
27 | @class YPBarConfiguration;
28 |
29 | @interface UIToolbar (YPConfigure)
30 |
31 | - (void) yp_applyBarConfiguration:(YPBarConfiguration *)configure;
32 |
33 | @end
34 |
--------------------------------------------------------------------------------
/YPNavigationBarTransition/internal/UIToolbar+YPConfigure.m:
--------------------------------------------------------------------------------
1 | /*
2 | MIT License
3 |
4 | Copyright (c) 2017 yiplee
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | #import "UIToolbar+YPConfigure.h"
26 | #import "YPBarConfiguration.h"
27 | #import "UIImage+YPConfigure.h"
28 |
29 | @implementation UIToolbar (YPConfigure)
30 |
31 | - (void) yp_applyBarConfiguration:(YPBarConfiguration *)configure {
32 | self.barStyle = configure.barStyle;
33 |
34 | UIImage* const transpanrentImage = [UIImage yp_transparentImage];
35 | if (configure.transparent) {
36 | if (@available(iOS 13.0, *)) {
37 | UIToolbarAppearance *appearance = [[self standardAppearance] copy];
38 | [appearance configureWithTransparentBackground];
39 | if (@available(iOS 15.0, *)) {
40 | self.scrollEdgeAppearance = appearance;
41 | }
42 | self.standardAppearance = appearance;
43 | } else {
44 | self.translucent = YES;
45 | [self setBackgroundImage:transpanrentImage forToolbarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
46 | }
47 | } else {
48 | if (@available(iOS 13.0, *)) {
49 | UIToolbarAppearance *appearance = [[self standardAppearance] copy];
50 | if (configure.translucent) {
51 | [appearance configureWithDefaultBackground];
52 | UIBlurEffectStyle effectStyle = configure.barStyle == UIBarStyleDefault ? UIBlurEffectStyleLight : UIBlurEffectStyleDark;
53 | appearance.backgroundEffect = [UIBlurEffect effectWithStyle:effectStyle];
54 | } else {
55 | [appearance configureWithOpaqueBackground];
56 | }
57 | if (configure.backgroundImage) {
58 | appearance.backgroundImage = configure.backgroundImage;
59 | } else if (configure.backgroundColor) {
60 | appearance.backgroundColor = configure.backgroundColor;
61 | }
62 | if (!configure.shadowImage) {
63 | appearance.shadowImage = nil;
64 | appearance.shadowColor = nil;
65 | }
66 | if (@available(iOS 15.0, *)) {
67 | self.scrollEdgeAppearance = appearance;
68 | }
69 | self.standardAppearance = appearance;
70 | } else {
71 | self.translucent = configure.translucent;
72 | UIImage* backgroundImage = configure.backgroundImage;
73 | if (!backgroundImage && configure.backgroundColor) {
74 | backgroundImage = [UIImage yp_imageWithColor:configure.backgroundColor];
75 | }
76 | [self setBackgroundImage:backgroundImage forToolbarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
77 | }
78 | }
79 |
80 | UIImage* shadowImage = configure.shadowImage ? nil : transpanrentImage;
81 | [self setShadowImage:shadowImage forToolbarPosition:UIBarPositionAny];
82 | }
83 |
84 | @end
85 |
--------------------------------------------------------------------------------
/YPNavigationBarTransition/internal/YPBarConfiguration.h:
--------------------------------------------------------------------------------
1 | /*
2 | MIT License
3 |
4 | Copyright (c) 2017 yiplee
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | #import
26 |
27 | NS_ASSUME_NONNULL_BEGIN
28 |
29 | @interface YPBarConfiguration : NSObject
30 |
31 | @property (nonatomic, assign, readonly) BOOL hidden;
32 | @property (nonatomic, assign, readonly) UIBarStyle barStyle;
33 | @property (nonatomic, assign, readonly) BOOL translucent;
34 | @property (nonatomic, assign, readonly) BOOL transparent;
35 | @property (nonatomic, assign, readonly) BOOL shadowImage;
36 | @property (nonatomic, strong, readonly) UIColor *tintColor;
37 | @property (nonatomic, strong, readonly, nullable) UIColor *backgroundColor;
38 | @property (nonatomic, strong, readonly, nullable) UIImage *backgroundImage;
39 | @property (nonatomic, strong, readonly, nullable) NSString *backgroundImageIdentifier;
40 |
41 | - (instancetype) init NS_UNAVAILABLE;
42 | - (instancetype) initWithBarConfigurations:(YPNavigationBarConfigurations)configurations
43 | tintColor:(nullable UIColor*) tintColor
44 | backgroundColor:(nullable UIColor *)backgroundColor
45 | backgroundImage:(nullable UIImage *)backgroundImage
46 | backgroundImageIdentifier:(nullable NSString*)backgroundImageIdentifier NS_DESIGNATED_INITIALIZER;
47 | @end
48 |
49 | @interface YPBarConfiguration (YPBarTransition)
50 |
51 | - (instancetype) initWithBarConfigurationOwner:(id)owner;
52 |
53 | - (BOOL) isVisible;
54 |
55 | - (BOOL) useSystemBarBackground;
56 |
57 | @end
58 |
59 | NS_ASSUME_NONNULL_END
60 |
--------------------------------------------------------------------------------
/YPNavigationBarTransition/internal/YPBarConfiguration.m:
--------------------------------------------------------------------------------
1 | /*
2 | MIT License
3 |
4 | Copyright (c) 2017 yiplee
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | #import "YPBarConfiguration.h"
26 |
27 | @implementation YPBarConfiguration
28 |
29 | - (instancetype) init {
30 | return [self initWithBarConfigurations:YPNavigationBarConfigurationsDefault
31 | tintColor:nil
32 | backgroundColor:nil
33 | backgroundImage:nil
34 | backgroundImageIdentifier:nil];
35 | }
36 |
37 | - (instancetype) initWithBarConfigurations:(YPNavigationBarConfigurations)configurations
38 | tintColor:(UIColor *)tintColor
39 | backgroundColor:(UIColor *)backgroundColor
40 | backgroundImage:(UIImage *)backgroundImage
41 | backgroundImageIdentifier:(NSString *)backgroundImageIdentifier {
42 | self = [super init];
43 | if (!self) return nil;
44 |
45 | do {
46 | _hidden = (configurations & YPNavigationBarHidden) > 0;
47 |
48 | _barStyle = (configurations & YPNavigationBarStyleBlack) > 0 ? UIBarStyleBlack : UIBarStyleDefault;
49 | if (!tintColor) {
50 | tintColor = _barStyle == UIBarStyleBlack ? [UIColor whiteColor] : [UIColor blackColor];
51 | }
52 | _tintColor = tintColor;
53 |
54 | if (_hidden) break;
55 |
56 | _transparent = (configurations & YPNavigationBarBackgroundStyleTransparent) > 0;
57 | if (_transparent) break;
58 |
59 | // show shadow image only if not transparent
60 | _shadowImage = (configurations & YPNavigationBarShowShadowImage) > 0;
61 | _translucent = (configurations & YPNavigationBarBackgroundStyleOpaque) == 0;
62 |
63 | if ((configurations & YPNavigationBarBackgroundStyleImage) > 0 && backgroundImage) {
64 | _backgroundImage = backgroundImage;
65 | _backgroundImageIdentifier = [backgroundImageIdentifier copy];
66 | } else if (configurations & YPNavigationBarBackgroundStyleColor){
67 | _backgroundColor = backgroundColor;
68 | }
69 | } while (0);
70 |
71 | return self;
72 | }
73 |
74 | @end
75 |
76 | @implementation YPBarConfiguration (YPBarTransition)
77 |
78 | - (instancetype) initWithBarConfigurationOwner:(id)owner {
79 | YPNavigationBarConfigurations configurations = [owner yp_navigtionBarConfiguration];
80 | UIColor *tintColor = [owner yp_navigationBarTintColor];
81 |
82 | UIImage *backgroundImage = nil;
83 | NSString *imageIdentifier = nil;
84 | UIColor *backgroundColor = nil;
85 |
86 | if (!(configurations & YPNavigationBarBackgroundStyleTransparent)) {
87 | if (configurations & YPNavigationBarBackgroundStyleImage) {
88 | backgroundImage = [owner yp_navigationBackgroundImageWithIdentifier:&imageIdentifier];
89 | } else if (configurations & YPNavigationBarBackgroundStyleColor) {
90 | backgroundColor = [owner yp_navigationBackgroundColor];
91 | }
92 | }
93 |
94 | return [self initWithBarConfigurations:configurations
95 | tintColor:tintColor
96 | backgroundColor:backgroundColor
97 | backgroundImage:backgroundImage
98 | backgroundImageIdentifier:imageIdentifier];
99 | }
100 |
101 | - (BOOL) isVisible {
102 | return !self.hidden && !self.transparent;
103 | }
104 |
105 | - (BOOL) useSystemBarBackground {
106 | return !self.backgroundColor && !self.backgroundImage;
107 | }
108 |
109 | @end
110 |
--------------------------------------------------------------------------------
/YPNavigationBarTransition/internal/YPNavigationBarTransitionCenterInternal.h:
--------------------------------------------------------------------------------
1 | /*
2 | MIT License
3 |
4 | Copyright (c) 2017 yiplee
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | #import
26 | #import
27 |
28 | BOOL YPTransitionNeedShowFakeBar(YPBarConfiguration *from,YPBarConfiguration *to);
29 |
30 | @interface YPNavigationBarTransitionCenter ()
31 |
32 | @property (nonatomic, strong) UIToolbar *fromViewControllerFakeBar;
33 | @property (nonatomic, strong) UIToolbar *toViewControllerFakeBar;
34 |
35 | @property (nonatomic, strong, readonly) YPBarConfiguration *defaultBarConfigure;
36 |
37 | @end
38 |
--------------------------------------------------------------------------------
/YPNavigationBarTransition/internal/YPNavigationControllerDelegateProxy.h:
--------------------------------------------------------------------------------
1 | //
2 | // YPNavigationControllerDelegateProxy.h
3 | // YPNavigationBarTransition
4 | //
5 | // Created by Guoyin Lee on 2018/4/25.
6 | // Copyright © 2018 yiplee. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | NS_ASSUME_NONNULL_BEGIN
12 |
13 | @class YPNavigationController;
14 | @protocol UINavigationControllerDelegate;
15 |
16 | @interface YPNavigationControllerDelegateProxy : NSProxy
17 |
18 | - (instancetype) initWithNavigationTarget:(nullable id)navigationTarget
19 | interceptor:(YPNavigationController *)interceptor;
20 | - (instancetype) init NS_UNAVAILABLE;
21 | + (instancetype) new NS_UNAVAILABLE;
22 |
23 | NS_ASSUME_NONNULL_END
24 |
25 | @end
26 |
--------------------------------------------------------------------------------
/YPNavigationBarTransition/internal/YPNavigationControllerDelegateProxy.m:
--------------------------------------------------------------------------------
1 | //
2 | // YPNavigationControllerDelegateProxy.m
3 | // YPNavigationBarTransition
4 | //
5 | // Created by Guoyin Lee on 2018/4/25.
6 | // Copyright © 2018 yiplee. All rights reserved.
7 | //
8 |
9 | #import "YPNavigationControllerDelegateProxy.h"
10 | #import
11 |
12 | static BOOL isInterceptedSelector(SEL sel) {
13 | return (
14 | sel == @selector(navigationController:willShowViewController:animated:) ||
15 | sel == @selector(navigationController:didShowViewController:animated:)
16 | );
17 | }
18 |
19 | @implementation YPNavigationControllerDelegateProxy {
20 | __weak id _navigationTarget;
21 | __weak YPNavigationController *_interceptor;
22 | }
23 |
24 | - (instancetype) initWithNavigationTarget:(nullable id)navigationTarget
25 | interceptor:(YPNavigationController *)interceptor {
26 | NSParameterAssert(interceptor != nil);
27 | if (self) {
28 | _navigationTarget = navigationTarget;
29 | _interceptor = interceptor;
30 | }
31 |
32 | return self;
33 | }
34 |
35 | - (BOOL)respondsToSelector:(SEL)aSelector {
36 | return isInterceptedSelector(aSelector)
37 | || [_navigationTarget respondsToSelector:aSelector];
38 | }
39 |
40 | - (id)forwardingTargetForSelector:(SEL)aSelector {
41 | return isInterceptedSelector(aSelector) ? _interceptor : _navigationTarget;
42 | }
43 |
44 | - (void)forwardInvocation:(NSInvocation *)invocation {
45 | void *nullPointer = NULL;
46 | [invocation setReturnValue:&nullPointer];
47 | }
48 |
49 | - (NSMethodSignature *)methodSignatureForSelector:(SEL)selector {
50 | return [NSObject instanceMethodSignatureForSelector:@selector(init)];
51 | }
52 |
53 | @end
54 |
--------------------------------------------------------------------------------
/YPNavigationBarTransitionTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 |
22 |
23 |
--------------------------------------------------------------------------------
/YPNavigationBarTransitionTests/barStyleDiffSpec.m:
--------------------------------------------------------------------------------
1 | //
2 | // barStyleDiffSpec.m
3 | // YPNavigationBarTransition
4 | //
5 | // Created by Guoyin Lee on 27/12/2017.
6 | // Copyright 2017 yiplee. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "YPNavigationBarTransitionCenterInternal.h"
11 | #import "TranslucentBlackBarStyleObject.h"
12 | #import "ColorNavigationBarStyleObject.h"
13 |
14 | SPEC_BEGIN(barStyleDiffSpec)
15 |
16 | describe(@"barStyleDiff", ^{
17 | let(translucentBlackStyle, ^id{
18 | TranslucentBlackBarStyleObject *object = [TranslucentBlackBarStyleObject new];
19 | return [[YPBarConfiguration alloc] initWithBarConfigurationOwner:object];
20 | });
21 |
22 | let(WhitColorBarStyle, ^id{
23 | ColorNavigationBarStyleObject *object = [ColorNavigationBarStyleObject new];
24 | object.backgroundColor = [UIColor whiteColor];
25 | return [[YPBarConfiguration alloc] initWithBarConfigurationOwner:object];
26 | });
27 |
28 | context(@"translucent black bar", ^{
29 | it(@"configure style should be", ^{
30 | YPBarConfiguration *conf = translucentBlackStyle;
31 | [[conf shouldNot] beNil];
32 | [[theValue(conf.hidden) should] beNo];
33 | [[theValue(conf.transparent) should] beNo];
34 | [[theValue(conf.translucent) should] beYes];
35 | [[theValue(conf.barStyle) should] equal:@(UIBarStyleBlack)];
36 | [[conf.tintColor should] equal:[UIColor whiteColor]];
37 | [[conf.backgroundColor should] beNil];
38 | [[conf.backgroundImage should] beNil];
39 | });
40 |
41 | it(@"should be visible & use system blur background", ^{
42 | YPBarConfiguration *conf = translucentBlackStyle;
43 | [[conf shouldNot] beNil];
44 | [[theValue(conf.isVisible) should] beYes];
45 | [[theValue(conf.useSystemBarBackground) should] beYes];
46 | });
47 | });
48 |
49 | context(@"color bar", ^{
50 | it(@"configure style should be", ^{
51 | YPBarConfiguration *conf = WhitColorBarStyle;
52 | [[conf shouldNot] beNil];
53 | [[theValue(conf.hidden) should] beNo];
54 | [[theValue(conf.transparent) should] beNo];
55 | [[theValue(conf.translucent) should] beYes];
56 | [[theValue(conf.barStyle) should] equal:@(UIBarStyleDefault)];
57 | [[conf.tintColor should] equal:[UIColor blackColor]];
58 | [[conf.backgroundColor should] beNonNil];
59 | [[conf.backgroundImage should] beNil];
60 | });
61 |
62 | it(@"should be visible & not use system blur background", ^{
63 | YPBarConfiguration *conf = WhitColorBarStyle;
64 | [[conf shouldNot] beNil];
65 | [[theValue(conf.isVisible) should] beYes];
66 | [[theValue(conf.useSystemBarBackground) shouldNot] beYes];
67 | });
68 | });
69 |
70 | context(@"diff bar style", ^{
71 | it(@"should use fake bar", ^{
72 | BOOL useFakeBar = YPTransitionNeedShowFakeBar(WhitColorBarStyle, translucentBlackStyle);
73 | [[theValue(useFakeBar) should] beYes];
74 | });
75 | });
76 | });
77 |
78 | SPEC_END
79 |
--------------------------------------------------------------------------------
/YPNavigationBarTransitionTests/objects/ColorNavigationBarStyleObject.h:
--------------------------------------------------------------------------------
1 | //
2 | // ColorNavigationBarStyleObject.h
3 | // YPNavigationBarTransitionTests
4 | //
5 | // Created by Li Guoyin on 2017/12/30.
6 | // Copyright © 2017年 yiplee. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 |
12 | @interface ColorNavigationBarStyleObject : NSObject
13 |
14 | @property (nonatomic, strong) UIColor *backgroundColor;
15 |
16 | @end
17 |
--------------------------------------------------------------------------------
/YPNavigationBarTransitionTests/objects/ColorNavigationBarStyleObject.m:
--------------------------------------------------------------------------------
1 | //
2 | // ColorNavigationBarStyleObject.m
3 | // YPNavigationBarTransitionTests
4 | //
5 | // Created by Li Guoyin on 2017/12/30.
6 | // Copyright © 2017年 yiplee. All rights reserved.
7 | //
8 |
9 | #import "ColorNavigationBarStyleObject.h"
10 |
11 | @implementation ColorNavigationBarStyleObject
12 |
13 | - (YPNavigationBarConfigurations) yp_navigtionBarConfiguration {
14 | return YPNavigationBarConfigurationsDefault | YPNavigationBarBackgroundStyleColor;
15 | }
16 |
17 | - (UIColor *) yp_navigationBarTintColor {
18 | return nil;
19 | }
20 |
21 | - (UIColor *) yp_navigationBackgroundColor {
22 | return self.backgroundColor;
23 | }
24 |
25 | @end
26 |
--------------------------------------------------------------------------------
/YPNavigationBarTransitionTests/objects/TranslucentBlackBarStyleObject.h:
--------------------------------------------------------------------------------
1 | //
2 | // TranslucentBlackBarStyleObject.h
3 | // YPNavigationBarTransitionTests
4 | //
5 | // Created by Guoyin Lee on 27/12/2017.
6 | // Copyright © 2017 yiplee. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 |
12 | @interface TranslucentBlackBarStyleObject : NSObject
13 |
14 | @end
15 |
--------------------------------------------------------------------------------
/YPNavigationBarTransitionTests/objects/TranslucentBlackBarStyleObject.m:
--------------------------------------------------------------------------------
1 | //
2 | // TranslucentBlackBarStyleObject.m
3 | // YPNavigationBarTransitionTests
4 | //
5 | // Created by Guoyin Lee on 27/12/2017.
6 | // Copyright © 2017 yiplee. All rights reserved.
7 | //
8 |
9 | #import "TranslucentBlackBarStyleObject.h"
10 |
11 | @implementation TranslucentBlackBarStyleObject
12 |
13 | - (YPNavigationBarConfigurations) yp_navigtionBarConfiguration {
14 | return YPNavigationBarConfigurationsDefault | YPNavigationBarStyleBlack;
15 | }
16 |
17 | - (UIColor *) yp_navigationBarTintColor {
18 | return [UIColor whiteColor];
19 | }
20 |
21 | @end
22 |
--------------------------------------------------------------------------------
/docs/how_to_use_CN.markdown:
--------------------------------------------------------------------------------
1 | # 怎么使用 YPNavigationBarTransition
2 |
3 | YPNavigationBarTransition 依靠 UINavigationControllerDelegate 的 willShow & didShow 驱动来实现自动管理 navigationBar 的切换。
4 | 对于每一个对 navigationBar 的样式有自定义需求的 viewController,可以通过实现 `YPNavigationBarConfigureStyle` 协议来实现。
5 | 每次 navigationController push 或者 pop viewController 的时候,YPNavigationBarTransition 通过对比当前 navigationBar
6 | 的样式和目标 viewController 指定的样式来判断是否需要添加 fake bar (用 UIToolbar)来模拟 navigation bar 的切换。
7 |
8 | ## `YPNavigationBarConfigureStyle` 协议
9 |
10 | ```objective-c
11 | typedef NS_ENUM(NSUInteger, YPNavigationBarConfigurations) {
12 | /*
13 | * 是否隐藏 navigation bar,默认是 show。
14 | */
15 | YPNavigationBarShow = 0,
16 | YPNavigationBarHidden = 1,
17 | /*
18 | * YPNavigationBarStyleLight = UIbarStyleDefault
19 | * YPNavigationBarStyleBlack = UIbarStyleBlack
20 | *
21 | * bar style 会影响 status bar 的样式,为 black 的时候 status bar 是白色,light 的时候是黑色。
22 | * 当没有自定义 background color 和 background image 的时候,navigation bar 的颜色也由 bar style 决定
23 | * 另外如果没有提供有效的 tintColor,YPNavigationBarTransition 将根据 bar style 自动设置 tintColor
24 | */
25 | YPNavigationBarStyleLight = 0 << 4, // UIbarStyleDefault
26 | YPNavigationBarStyleBlack = 1 << 4, // UIbarStyleBlack
27 | /*
28 | * translucent = 半透明,transparent = 全透明,opaque = 不透明
29 | */
30 | YPNavigationBarBackgroundStyleTranslucent = 0 << 8,
31 | YPNavigationBarBackgroundStyleOpaque = 1 << 8,
32 | YPNavigationBarBackgroundStyleTransparent = 2 << 8,
33 | /*
34 | * 使用颜色或者图片来配置 navigation bar 的 background image
35 | */
36 | YPNavigationBarBackgroundStyleNone = 0 << 16,
37 | YPNavigationBarBackgroundStyleColor = 1 << 16,
38 | YPNavigationBarBackgroundStyleImage = 2 << 16,
39 | YPNavigationBarConfigurationsDefault = 0,
40 | /*
41 | * 是否显示 UINavigationBar 下方的横线,默认不显示
42 | * 在全透明 (Transparent) 的时候,将忽略 shadow image 的设置
43 | */
44 | YPNavigationBarShowShadowImage = 1 << 20,
45 | };
46 |
47 | - (YPNavigationBarConfigurations) yp_navigtionBarConfiguration;
48 | ```
49 |
50 | **[required]** 返回 navigation bar 配置
51 |
52 | ```objective-c
53 | - (UIColor *) yp_navigationBarTintColor;
54 | ```
55 |
56 | **[required]** navigation bar tint color,影响 bar item 的颜色;
57 | 如果返回 nil,bar style 是 YPNavigationBarStyleBlack 的话,将使用白色作为 tintColor,
58 | bar style 是 YPNavigationBarStyleLight 的话,将使用黑色作为 tintColor。
59 |
60 | ```objective-c
61 | - (UIImage *) yp_navigationBackgroundImageWithIdentifier:(NSString **)identifier;
62 | ```
63 |
64 | **[optional]** navigation bar background image,`identifier`作为 image 的 id 使用,同 id 的图片看作是同一张图片,在判断是否需要使用 fake bar 的时候需要用到。如果 bar configuration使用了 YPNavigationBarBackgroundStyleImage,这个方法一定要实现。
65 |
66 | ```objective-c
67 | - (UIColor *) yp_navigationBackgroundColor;
68 | ```
69 |
70 | **[optional]** navigation bar background color。如果 bar configuration
71 | 使用了 YPNavigationBarBackgroundStyleColor,这个方法一定要实现。
72 |
73 | ## 动态改变 NavigationBar 的样式
74 |
75 | 在合适的时机调用 UIViewController 的方法 yp_refreshNavigationBarStyle,即可将 UIViewController 实现的 `YPNavigationBarConfigureStyle` 当前
76 | 样式同步到 navigation bar 上。参考 Example 里面的 [YPGradientDemoViewController](https://github.com/yiplee/YPNavigationBarTransition/blob/master/Examples/share/YPGradientDemoViewController.m#L148)
77 |
78 | ## 最佳实践
79 |
80 | **默认 YPNavigationBarConfigureStyle 实现** 自 **2.0.2** 版本开始,封装了 center 的 YPNavigationController 已内置在 framework 内,只需要给 YPNavigationController 加一个 Category 实现 YPNavigationBarConfigureStyle 协议即可。
81 |
82 | **NavigationItem Title** 建议使用一个 UILabel 作为 navigationItem 的 titleView 来展现页面 title,这样可以让页面完全自己控制 title 的颜色、
83 | 字体等等,并且还可以实现 subtitle。可以参考 Example 里面的 [YPNavigationTitleLabel](https://github.com/yiplee/YPNavigationBarTransition/blob/master/Examples/share/YPNavigationTitleLabel.m)。
84 |
85 | **ScrollView 跳动问题** 在转场过程中,navigationBar 的 translucent 属性可能发生了改变,
86 | 然后导致了 scrollView 的 frame 和 contentInset 发生改变,页面展示内容位置变化。如果遇到这种情况,建议设置对应 controller 的 extendedLayoutIncludesOpaqueBars (IB 里面的 under opaque bar) 为 YES,即可避开这个问题。
87 |
88 | ## ⚠️ 注意
89 |
90 | - 不支持 iOS 11 新增的 navigationBar large title。
91 | - 使用默认配置的页面,不用实现 YPNavigationBarConfigureStyle 协议。
92 |
--------------------------------------------------------------------------------
/run_unit_test.sh:
--------------------------------------------------------------------------------
1 | bundler install
2 | bundle exec pod install
3 | xcodebuild analyze test -workspace YPNavigationBarTransition.xcworkspace -scheme YPNavigationBarTransitionLibrary -sdk iphonesimulator -destination "OS=11.3,name=iPhone 8" -configuration Debug ONLY_ACTIVE_ARCH=NO CODE_SIGNING_REQUIRED=NO | bundle exec xcpretty -c
4 |
--------------------------------------------------------------------------------
/screenshots/gif-01.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yiplee/YPNavigationBarTransition/7543ff1ef819003bef06d8a0f7c1e93e2b2b3fbe/screenshots/gif-01.gif
--------------------------------------------------------------------------------
/screenshots/gif-02.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yiplee/YPNavigationBarTransition/7543ff1ef819003bef06d8a0f7c1e93e2b2b3fbe/screenshots/gif-02.gif
--------------------------------------------------------------------------------
/screenshots/gif-03.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yiplee/YPNavigationBarTransition/7543ff1ef819003bef06d8a0f7c1e93e2b2b3fbe/screenshots/gif-03.gif
--------------------------------------------------------------------------------