You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

230 lines
9.1 KiB

2 years ago
/**
* Tencent is pleased to support the open source community by making QMUI_iOS available.
* Copyright (C) 2016-2020 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
//
// QMUIHelper.h
// qmui
//
// Created by QMUI Team on 14/10/25.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface QMUIHelper : NSObject
+ (instancetype)sharedInstance;
@end
@interface QMUIHelper (Bundle)
/// 获取 QMUIKit.framework Images.xcassets 内的图片资源
/// @param name 图片名
+ (nullable UIImage *)imageWithName:(NSString *)name;
@end
@interface QMUIHelper (SystemVersion)
+ (NSInteger)numbericOSVersion;
+ (NSComparisonResult)compareSystemVersion:(nonnull NSString *)currentVersion toVersion:(nonnull NSString *)targetVersion;
+ (BOOL)isCurrentSystemAtLeastVersion:(nonnull NSString *)targetVersion;
+ (BOOL)isCurrentSystemLowerThanVersion:(nonnull NSString *)targetVersion;
@end
@interface QMUIHelper (DynamicType)
/// 返回当前 contentSize 的 level,这个值可以在设置里面的“字体大小”查看,辅助功能里面有个“更大字体”可以设置更大的字体,不过这里我们这个接口将更大字体都做了统一,都返回“字体大小”里面最大值。
/// Returns the level of contentSize
/// The value can be set in Settings - Display & Brightness - Text Size as well as in General - Accessibility - Larger Text
/// This method returns the value set by user or the maximum value in Text Size, whichever is smaller
+ (nonnull NSNumber *)preferredContentSizeLevel;
/// 设置当前 cell 的高度,heights 是有七个数值的数组,对于不支持的iOS版本,则选择中间的值返回。
/// Sets height of the cell; Heights consist of 7 numberic values; Returns the middle value on legacy iOS versions.
+ (CGFloat)heightForDynamicTypeCell:(nonnull NSArray *)heights;
@end
@interface QMUIHelper (Keyboard)
/**
* App NO
* Returns the visibility of the keybord. Default value is NO.
*/
+ (BOOL)isKeyboardVisible;
/**
* App window 使 `isKeyboardVisible` 便 `lastKeyboardHeightInApplicationWindowWhenVisible`
*/
+ (CGFloat)lastKeyboardHeightInApplicationWindowWhenVisible;
/**
* frame相关
* @warning iOS8以下的系统在横屏时得到的rect使<code>keyboardHeightWithNotification:inView:</code>rect转换坐标系
*/
+ (CGRect)keyboardRectWithNotification:(nullable NSNotification *)notification;
/// 获取当前键盘的高度,注意高度可能为0(例如第三方键盘会发出两次notification,其中第一次的高度就为0)
+ (CGFloat)keyboardHeightWithNotification:(nullable NSNotification *)notification;
/**
* iPad那种[QMUIHelper keyboardRectWithNotification]rect里有一部分是超出屏幕rect的高度来计算就会与意图相悖
* @param notification UINotification对象
* @param view View的键盘高度nil[QMUIHelper keyboardHeightWithNotification:]
* @warning view.window为空View尚不可见使App默认的UIWindow来做坐标转换
* @return view里的可视高度
*/
+ (CGFloat)keyboardHeightWithNotification:(nullable NSNotification *)notification inView:(nullable UIView *)view;
/// 获取键盘显示/隐藏的动画时长,注意返回值可能为0
+ (NSTimeInterval)keyboardAnimationDurationWithNotification:(nullable NSNotification *)notification;
/// 获取键盘显示/隐藏的动画时间函数
+ (UIViewAnimationCurve)keyboardAnimationCurveWithNotification:(nullable NSNotification *)notification;
/// 获取键盘显示/隐藏的动画时间函数
+ (UIViewAnimationOptions)keyboardAnimationOptionsWithNotification:(nullable NSNotification *)notification;
@end
@interface QMUIHelper (AudioSession)
/**
*
*
* @param speaker NO则听筒
* @param temporary 使kAudioSessionProperty_OverrideAudioRoute还是kAudioSessionProperty_OverrideCategoryDefaultToSpeaker:http://km.oa.com/group/gyui/articles/show/235957
*/
+ (void)redirectAudioRouteWithSpeaker:(BOOL)speaker temporary:(BOOL)temporary;
/**
* category
*
* @param category 使iOS7的categoryiOS6的会自动适配
*/
+ (void)setAudioSessionCategory:(nullable NSString *)category;
@end
@interface QMUIHelper (UIGraphic)
/// 获取一像素的大小
+ (CGFloat)pixelOne;
/// 判断size是否超出范围
+ (void)inspectContextSize:(CGSize)size;
/// context是否合法
+ (void)inspectContextIfInvalidatedInDebugMode:(CGContextRef)context;
+ (BOOL)inspectContextIfInvalidatedInReleaseMode:(CGContextRef)context;
@end
@interface QMUIHelper (Device)
/// 如 iPhone12,5、iPad6,8
+ (nonnull NSString *)deviceModel;
/// 如 iPhone 11 Pro Max、iPad Pro (12.9 inch)
+ (nonnull NSString *)deviceName;
+ (BOOL)isIPad;
+ (BOOL)isIPod;
+ (BOOL)isIPhone;
+ (BOOL)isSimulator;
/// 带物理凹槽的刘海屏或者使用 Home Indicator 类型的设备
+ (BOOL)isNotchedScreen;
/// 将屏幕分为普通和紧凑两种,这个方法用于判断普通屏幕
+ (BOOL)isRegularScreen;
/// iPhone XS Max / 11 Pro Max
+ (BOOL)is65InchScreen;
/// iPhone XR / 11
+ (BOOL)is61InchScreen;
/// iPhone X / XS / 11Pro
+ (BOOL)is58InchScreen;
/// iPhone 8 Plus
+ (BOOL)is55InchScreen;
/// iPhone 8
+ (BOOL)is47InchScreen;
/// iPhone 5
+ (BOOL)is40InchScreen;
/// iPhone 4
+ (BOOL)is35InchScreen;
+ (CGSize)screenSizeFor65Inch;
+ (CGSize)screenSizeFor61Inch;
+ (CGSize)screenSizeFor58Inch;
+ (CGSize)screenSizeFor55Inch;
+ (CGSize)screenSizeFor47Inch;
+ (CGSize)screenSizeFor40Inch;
+ (CGSize)screenSizeFor35Inch;
+ (CGFloat)preferredLayoutAsSimilarScreenWidthForIPad;
// 用于获取 isNotchedScreen 设备的 insets,注意对于 iPad Pro 11-inch 这种无刘海凹槽但却有使用 Home Indicator 的设备,它的 top 返回0,bottom 返回 safeAreaInsets.bottom 的值
+ (UIEdgeInsets)safeAreaInsetsForDeviceWithNotch;
/// 判断当前设备是否高性能设备,只会判断一次,以后都直接读取结果,所以没有性能问题
+ (BOOL)isHighPerformanceDevice;
/// 系统设置里是否开启了“放大显示-试图-放大”,支持放大模式的 iPhone 设备可在官方文档中查询 https://support.apple.com/zh-cn/guide/iphone/iphd6804774e/ios
+ (BOOL)isZoomedMode;
/**
iPad iPad [UIScreen mainScreen].bounds.size
@return
*/
+ (CGSize)applicationSize;
@end
@interface QMUIHelper (UIApplication)
/**
* App的主要window置灰`resetDimmedApplicationWindow`
*/
+ (void)dimmedApplicationWindow;
/**
* App的主要window的置灰操作`dimmedApplicationWindow`
*/
+ (void)resetDimmedApplicationWindow;
/**
* StatusBarStyle
* @note iOS 13 UIStatusBarStyleDefault iOS 13 UIStatusBarStyleDefault user interface style QMUIStatusBarStyleDarkContent UIStatusBarStyleDefault
* @return iOS 13 UIStatusBarStyleDarkContent iOS 12 UIStatusBarStyleDefault
*/
+ (UIStatusBarStyle)statusBarStyleDarkContent;
@end
@interface QMUIHelper (Animation)
/**
animationBlock completionBlock completionBlock [UINavigationController pushViewController:animated:YES] UIScrollView 使
@param animationBlock
@param completionBlock
*/
+ (void)executeAnimationBlock:(nonnull __attribute__((noescape)) void (^)(void))animationBlock completionBlock:(nullable __attribute__((noescape)) void (^)(void))completionBlock;
@end
NS_ASSUME_NONNULL_END