Skip to content

Commit

Permalink
1.26.0 add new API cyl_forceUpdateInterfaceOrientation fix #376 fix #375
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenYilong committed May 28, 2019
1 parent 2b7345a commit 547578e
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 21 deletions.
4 changes: 2 additions & 2 deletions CYLTabBarController.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "CYLTabBarController"
s.version = "1.25.0"
s.version = "1.26.0"
s.summary = "Highly customizable tabBar and tabBarController for iOS"
s.description = "[EN]It is an iOS UI module library for adding animation to iOS tabbar items and icons with Lottie. [CN]【中国特色 TabBar】一行代码实现 Lottie 动画TabBar,支持中间带+号的TabBar样式,自带红点角标,支持动态刷新。【iOS12 & iPhone XS MAX supported】"
s.homepage = "https://github.com/ChenYilong/CYLTabBarController"
Expand All @@ -25,4 +25,4 @@ Pod::Spec.new do |s|
lottie.dependency "lottie-ios" , '~> 2.5.3'
end
end


2 changes: 0 additions & 2 deletions CYLTabBarController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,10 @@
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-CYLTabBarController/Pods-CYLTabBarController-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/CYLTabBarController/CYLTabBarController.framework",
"${BUILT_PRODUCTS_DIR}/lottie-ios/Lottie.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CYLTabBarController.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Lottie.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
Expand Down
3 changes: 2 additions & 1 deletion CYLTabBarController/CYLTabBarController.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#import "UITabBarItem+CYLBadgeExtention.h"
#import "UIBarButtonItem+CYLBadgeExtention.h"
#import "UIView+CYLBadgeExtention.h"
#import "NSObject+CYLLandscapeExtension.h"

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -38,7 +39,7 @@ FOUNDATION_EXTERN CGFloat CYLPlusButtonWidth;
FOUNDATION_EXTERN CGFloat CYLTabBarItemWidth;
FOUNDATION_EXTERN CGFloat CYLTabBarHeight;

@protocol CYLTabBarControllerDelegate <NSObject>
@protocol CYLTabBarControllerDelegate <NSObject, UITabBarControllerDelegate>
@optional
/*!
* @param tabBarController The tab bar controller containing viewController.
Expand Down
2 changes: 2 additions & 0 deletions CYLTabBarController/CYLTabBarController.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ - (void)viewDidLoad {
[super viewDidLoad];
if (CYL_IS_IPHONE_X) {
self.tabBarHeight = 83;
} else {
self.tabBarHeight = 49;
}
// 处理tabBar,使用自定义 tabBar 添加 发布按钮
[self setUpTabBar];
Expand Down
23 changes: 23 additions & 0 deletions CYLTabBarController/NSObject+CYLLandscapeExtension.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// CYLTabBarController.h
// CYLTabBarController
//
// v1.21.x Created by 微博@iOS程序犭袁 ( http://weibo.com/luohanchenyilong/ ) on 10/20/15.
// Copyright © 2018 https://github.com/ChenYilong . All rights reserved.
//

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface NSObject (CYLLandscapeExtension)

@property (nonatomic, assign, getter=cyl_isForceLandscape, setter=cyl_setIsForceLandscape:) BOOL cyl_isForceLandscape;

- (void)cyl_forceUpdateInterfaceOrientation:(UIInterfaceOrientation)orientation;

- (UIResponder<UIApplicationDelegate> *)cyl_sharedAppDelegate;

@end

NS_ASSUME_NONNULL_END
50 changes: 50 additions & 0 deletions CYLTabBarController/NSObject+CYLLandscapeExtension.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// CYLTabBarController.h
// CYLTabBarController
//
// v1.21.x Created by 微博@iOS程序犭袁 ( http://weibo.com/luohanchenyilong/ ) on 10/20/15.
// Copyright © 2018 https://github.com/ChenYilong . All rights reserved.
//

#import "NSObject+CYLLandscapeExtension.h"
#import <objc/runtime.h>

@implementation NSObject (CYLLandscapeExtension)

- (BOOL)cyl_isForceLandscape {
NSNumber *isForceLandscapeObject = objc_getAssociatedObject(self, @selector(cyl_isForceLandscape));
return [isForceLandscapeObject boolValue];
}

- (void)cyl_setIsForceLandscape:(BOOL)isForceLandscape {
NSNumber *isForceLandscapeObject = @(isForceLandscape);
objc_setAssociatedObject(self, @selector(cyl_isForceLandscape), isForceLandscapeObject, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (UIResponder<UIApplicationDelegate> *)cyl_sharedAppDelegate {
id<UIApplicationDelegate> appDelegate = [UIApplication sharedApplication].delegate;
return (UIResponder<UIApplicationDelegate> *)appDelegate;
}

- (void)cyl_forceUpdateInterfaceOrientation:(UIInterfaceOrientation)orientation {
UIResponder<UIApplicationDelegate> *appDelegate = [self cyl_sharedAppDelegate];
BOOL isForceLandscape = (UIInterfaceOrientationLandscapeLeft == orientation) || (UIInterfaceOrientationLandscapeRight == orientation);
appDelegate.cyl_isForceLandscape = isForceLandscape;
if ([appDelegate respondsToSelector:@selector(application:supportedInterfaceOrientationsForWindow:)]) {
[appDelegate application:[UIApplication sharedApplication] supportedInterfaceOrientationsForWindow:UIApplication.sharedApplication.keyWindow];
}
if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
NSNumber *num = [[NSNumber alloc]initWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] performSelector:@selector(setOrientation:)withObject:(id)num];
[UIViewController attemptRotationToDeviceOrientation];
SEL selector = NSSelectorFromString(@"setOrientation:");
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:[UIDevice currentDevice]];
int val = orientation;
[invocation setArgument:&val atIndex:2];
[invocation invoke];
}
}

@end
19 changes: 18 additions & 1 deletion Example/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
#import "CYLMainRootViewController.h"

@interface AppDelegate ()

@property (nonatomic, strong) NSMutableData *data;
@end

@implementation AppDelegate

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



[UIApplication sharedApplication].statusBarHidden = NO;
// 设置主窗口,并设置根控制器
self.window = [[UIWindow alloc]init];
Expand All @@ -29,6 +32,20 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
return YES;
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmethod-signatures"
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
//设置强制旋转屏幕
if (self.cyl_isForceLandscape) {
//只支持横屏
return UIInterfaceOrientationMaskLandscape;
} else {
//只支持竖屏
return UIInterfaceOrientationMaskPortrait;
}
}
#pragma clang diagnostic pop

/**
* 设置navigationBar样式
*/
Expand Down
6 changes: 5 additions & 1 deletion Example/CYLMainRootViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
//
#import <UIKit/UIKit.h>

@class CYLTabBarController;
#if __has_include(<CYLTabBarController/CYLTabBarController.h>)
#import <CYLTabBarController/CYLTabBarController.h>
#else
#import "CYLTabBarController.h"
#endif

NS_ASSUME_NONNULL_BEGIN

Expand Down
24 changes: 12 additions & 12 deletions Example/CYLMainRootViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ - (UIButton *)selectedCover {
- (void)setSelectedCoverShow:(BOOL)show {
UIControl *selectedTabButton = [[self cyl_tabBarController].viewControllers[0].tabBarItem cyl_tabButton];
[selectedTabButton cyl_replaceTabButtonWithNewView:self.selectedCover
show:show];
show:show];
if (show) {
[self addOnceScaleAnimationOnView:self.selectedCover];
}
Expand All @@ -84,7 +84,7 @@ - (void)addOnceScaleAnimationOnView:(UIView *)animationView {
+ (void)customizeInterfaceWithTabBarController:(CYLTabBarController *)tabBarController {
//设置导航栏
// [self setUpNavigationBarAppearance];
// [tabBarController hideTabBadgeBackgroundSeparator];
// [tabBarController hideTabBadgeBackgroundSeparator];
//添加小红点
//添加提示动画,引导用户点击
[tabBarController setViewDidLayoutSubViewsBlockInvokeOnce:YES block:^(CYLTabBarController *tabBarController) {
Expand All @@ -97,35 +97,35 @@ + (void)customizeInterfaceWithTabBarController:(CYLTabBarController *)tabBarCont
// [tab0 cyl_showBadge];
[viewController0 cyl_setBadgeBackgroundColor:RANDOM_COLOR];
[viewController0 cyl_setBadgeCenterOffset:CGPointMake(-5, 3)];
// [viewController0 cyl_setBadgeRadius:11/2];
// [viewController0 cyl_setBadgeRadius:11/2];
//以上对Badge的参数设置,需要在 cyl_showBadgeValue 调用之前执行。
[viewController0 cyl_showBadge];

// [tabBarController.viewControllers[1] cyl_setBadgeMargin:5];
// [tabBarController.viewControllers[2] cyl_setBadgeMargin:5];
// [tabBarController.viewControllers[3] cyl_setBadgeMargin:5];
// [tabBarController.viewControllers[4] cyl_setBadgeMargin:5];
// [tabBarController.viewControllers[1] cyl_setBadgeMargin:5];
// [tabBarController.viewControllers[2] cyl_setBadgeMargin:5];
// [tabBarController.viewControllers[3] cyl_setBadgeMargin:5];
// [tabBarController.viewControllers[4] cyl_setBadgeMargin:5];
[tabBarController.viewControllers[1] cyl_setBadgeBackgroundColor:RANDOM_COLOR];
[tabBarController.viewControllers[1] cyl_showBadgeValue:@"" animationType:CYLBadgeAnimationTypeScale];
[tabBarController.viewControllers[2] cyl_showBadgeValue:@"" animationType:CYLBadgeAnimationTypeShake];

NSString *testBadgeString = @"100";
// [tabBarController.viewControllers[3] cyl_setBadgeMargin:-5];
// [tabBarController.viewControllers[3] cyl_setBadgeMargin:-5];
CGSize size = [testBadgeString sizeWithAttributes:
@{NSFontAttributeName:
tabBarController.viewControllers[3].cyl_badgeFont}];
float labelHeight = ceilf(size.height);
// [tabBarController.viewControllers[3] cyl_setBadgeCornerRadius:(labelHeight+ tabBarController.viewControllers[3].cyl_badgeMargin)/2];
// float labelHeight = ceilf(size.height);
// [tabBarController.viewControllers[3] cyl_setBadgeCornerRadius:(labelHeight+ tabBarController.viewControllers[3].cyl_badgeMargin)/2];
[tabBarController.viewControllers[3] cyl_showBadgeValue:testBadgeString animationType:CYLBadgeAnimationTypeBounce];

[tabBarController.viewControllers[4] cyl_showBadgeValue:@"NEW" animationType:CYLBadgeAnimationTypeBreathe];
} @catch (NSException *exception) {}

//添加仿淘宝tabbar,第一个tab选中后有图标覆盖
if ([self cyl_tabBarController].selectedIndex != 0) {
return;
}
// tabBarController.selectedIndex = 1;
// tabBarController.selectedIndex = 1;
});
}];
}
Expand Down
10 changes: 10 additions & 0 deletions Example/Classes/Module/SameCity/CYLDetailsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ - (void)viewDidLoad {
[self.view addSubview:label];
}

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[self cyl_sharedAppDelegate] cyl_forceUpdateInterfaceOrientation:UIInterfaceOrientationLandscapeLeft];
}

- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[[self cyl_sharedAppDelegate] cyl_forceUpdateInterfaceOrientation:UIInterfaceOrientationPortrait];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
// [self cyl_popSelectTabBarChildViewControllerAtIndex:4 completion:^(__kindof UIViewController *selectedTabBarChildViewController) {
[self cyl_popSelectTabBarChildViewControllerForClassType:[CYLMineViewController class] completion:^(__kindof UIViewController *selectedTabBarChildViewController) {
Expand Down
7 changes: 5 additions & 2 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ target 'CYLTabBarController' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!

#pod 'CYLTabBarController', '~> 1.24.1' # 默认不依赖Lottie
pod 'CYLTabBarController/Lottie', '~> 1.24.1' # 依赖Lottie库
pod 'CYLTabBarController', '~> 1.26.0' # 默认不依赖Lottie
pod 'CYLTabBarController/Lottie', '~> 1.26.0' # 依赖Lottie库

#pod 'CYLTabBarController', :path => './'
#pod 'CYLTabBarController/Lottie', :path => './'

end

0 comments on commit 547578e

Please sign in to comment.