Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/QMUI/QMUI_iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoon committed Mar 28, 2017
2 parents 7d909f4 + 45dacdf commit bc6aba1
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 175 deletions.
5 changes: 4 additions & 1 deletion QMUIKit/UIComponents/QMUIModalPresentationViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ - (void)viewWillDisappear:(BOOL)animated {
void (^didHiddenCompletion)(BOOL finished) = ^(BOOL finished) {

if (self.containerWindow) {
[self.previousKeyWindow makeKeyWindow];
// 恢复 keyWindow 之前做一下检查,避免这个问题 https://github.com/QMUI/QMUI_iOS/issues/90
if ([[UIApplication sharedApplication] keyWindow] == self.containerWindow) {
[self.previousKeyWindow makeKeyWindow];
}
self.containerWindow.hidden = YES;
self.containerWindow.rootViewController = nil;
self.previousKeyWindow = nil;
Expand Down
9 changes: 6 additions & 3 deletions QMUIKit/UIComponents/QMUIPopupContainerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ typedef enum {
* 1. 调用 init 方法初始化。
* 2. 选择一种显示方式:
* 2.1 如果要添加到某个 UIView 上,则先设置浮层 hidden = YES,然后调用 addSubview: 把浮层添加到目标 UIView 上。
* 2.2 如果是轻量的场景用完即走,则 init 完浮层即可,无需设置 hidden,也无需调用 addSubview:。
* 2.2 如果是轻量的场景用完即走,则 init 完浮层即可,无需设置 hidden,也无需调用 addSubview:,在后面第 4 步里会自动把浮层添加到 UIWindow 上显示出来
* 3. 在适当的时机(例如 layoutSubviews: 或 viewDidLayoutSubviews:)调用 layoutWithTargetView: 让浮层参考目标 view 布局,或者调用 layoutWithTargetRectInScreenCoordinate: 让浮层参考基于屏幕坐标系里的一个 rect 来布局。
* 4. 调用 showWithAnimated: 或 showWithAnimated:completion: 显示浮层。
* 5. 调用 hideWithAnimated: 或 hideWithAnimated:completion: 隐藏浮层。
*
* @warning 如果使用方法 2.2,并且没有打开 automaticallyHidesWhenUserTap 属性,则记得在适当的时机(例如 viewWillDisappear:)隐藏浮层。
*
* 如果默认功能无法满足需求,可继承它重写一个子类,继承要点:
* 1. 初始化时要做的事情请放在 didInitialized 里。
* 2. 所有 subviews 请加到 contentView 上。
Expand All @@ -43,7 +45,8 @@ typedef enum {

@property(nonatomic, assign) BOOL debug;

/// 在浮层显示时,点击空白地方是否要自动隐藏浮层,仅在用方法 2 显示时有效。默认为 NO,也即需要代码手动调用才能隐藏。
/// 在浮层显示时,点击空白地方是否要自动隐藏浮层,仅在用方法 2 显示时有效。
/// 默认为 NO,也即需要手动调用代码去隐藏浮层。
@property(nonatomic, assign) BOOL automaticallyHidesWhenUserTap;

/// 所有subview都应该添加到contentView上,默认contentView.userInteractionEnabled = NO,需要事件操作时自行打开
Expand Down Expand Up @@ -94,7 +97,7 @@ typedef enum {
@property(nonatomic, strong) UIColor *backgroundColor UI_APPEARANCE_SELECTOR;
@property(nonatomic, strong) UIColor *highlightedBackgroundColor UI_APPEARANCE_SELECTOR;

/// 当使用方法 2 显示时,可修改背景遮罩的颜色,默认为 UIColorClear。
/// 当使用方法 2 显示并且打开了 automaticallyHidesWhenUserTap 时,可修改背景遮罩的颜色,默认为 UIColorMask,若非使用方法 2,或者没有打开 automaticallyHidesWhenUserTap,则背景遮罩为透明(可视为不存在背景遮罩)
@property(nonatomic, strong) UIColor *maskViewBackgroundColor UI_APPEARANCE_SELECTOR;
@property(nonatomic, strong) UIColor *shadowColor UI_APPEARANCE_SELECTOR;
@property(nonatomic, strong) UIColor *borderColor UI_APPEARANCE_SELECTOR;
Expand Down
13 changes: 10 additions & 3 deletions QMUIKit/UIComponents/QMUIPopupContainerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,10 @@ - (void)hideWithAnimated:(BOOL)animated completion:(void (^)(BOOL))completion {

- (void)hideCompletionWithWindowMode:(BOOL)windowMode completion:(void (^)(BOOL))completion {
if (windowMode) {
[self.previousKeyWindow makeKeyWindow];
// 恢复 keyWindow 之前做一下检查,避免类似问题 https://github.com/QMUI/QMUI_iOS/issues/90
if ([[UIApplication sharedApplication] keyWindow] == self.popupWindow) {
[self.previousKeyWindow makeKeyWindow];
}

// iOS 9 下(iOS 8 和 10 都没问题)需要主动移除,才能令 rootViewController 和 popupWindow 立即释放,不影响后续的 layout 判断,如果不加这两句,虽然 popupWindow 指针被置为 nil,但其实对象还存在,View 层级关系也还在
// https://github.com/QMUI/QMUI_iOS/issues/75
Expand Down Expand Up @@ -459,7 +462,11 @@ - (void)initPopupContainerViewWindowIfNeeded {
self.popupWindow.windowLevel = UIWindowLevelQMUIAlertView;
QMUIPopContainerViewController *viewController = [[QMUIPopContainerViewController alloc] init];
((QMUIPopContainerMaskControl *)viewController.view).popupContainerView = self;
viewController.view.backgroundColor = self.maskViewBackgroundColor;
if (self.automaticallyHidesWhenUserTap) {
viewController.view.backgroundColor = self.maskViewBackgroundColor;
} else {
viewController.view.backgroundColor = UIColorClear;
}
viewController.supportedOrientationMask = [QMUIHelper visibleViewController].supportedInterfaceOrientations;
self.popupWindow.rootViewController = viewController;// 利用 rootViewController 来管理横竖屏
[self.popupWindow.rootViewController.view addSubview:self];
Expand Down Expand Up @@ -557,7 +564,7 @@ + (void)setDefaultAppearance {
appearance.distanceBetweenTargetRect = 5;
appearance.safetyMarginsOfSuperview = UIEdgeInsetsMake(10, 10, 10, 10);
appearance.backgroundColor = UIColorWhite;
appearance.maskViewBackgroundColor = UIColorClear;
appearance.maskViewBackgroundColor = UIColorMask;
appearance.highlightedBackgroundColor = nil;
appearance.shadowColor = UIColorMakeWithRGBA(0, 0, 0, .1);
appearance.borderColor = UIColorGrayLighten;
Expand Down
3 changes: 3 additions & 0 deletions QMUIKit/UIKitExtensions/QMUISearchController.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,7 @@
* @param animated 是否要以动画的形式展示状态切换
*/
- (void)setActive:(BOOL)active animated:(BOOL)animated;

/// 进入搜索状态时是否要把原界面的 navigationBar 推走,默认为 YES,仅在 iOS 8 及以后有效
@property(nonatomic, assign) BOOL hidesNavigationBarDuringPresentation;
@end
23 changes: 19 additions & 4 deletions QMUIKit/UIKitExtensions/QMUISearchController.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ - (void)initTableView {
@interface QMUISearchDisplayController : UISearchDisplayController

@property(nonatomic, strong) UIView *customDimmingView;
@property(nonatomic, copy) void (^dimmingViewVisibleChangedBlock)(BOOL visible);
@end

@implementation QMUISearchDisplayController
Expand Down Expand Up @@ -85,9 +84,6 @@ - (UIColor *)_dimmingViewColor {
if (self.customDimmingView.superview != defaultDimmingView) {
[defaultDimmingView addSubview:self.customDimmingView];
}
if (self.dimmingViewVisibleChangedBlock) {
self.dimmingViewVisibleChangedBlock(self.isActive);
}
}
}

Expand Down Expand Up @@ -187,6 +183,8 @@ - (instancetype)initWithContentsViewController:(UIViewController *)viewControlle
self.searchDisplayController = [[QMUISearchDisplayController alloc] initWithSearchBar:self.searchBar contentsController:viewController];
self.searchDisplayController.delegate = self;
}

self.hidesNavigationBarDuringPresentation = YES;
}
return self;
}
Expand Down Expand Up @@ -256,6 +254,23 @@ - (void)setLaunchView:(UIView *)dimmingView {
}
}

- (BOOL)hidesNavigationBarDuringPresentation {
if (self.searchController) {
return self.searchController.hidesNavigationBarDuringPresentation;
} else {
NSLog(@"%s 仅支持 iOS 8 及以上版本", __func__);
return YES;
}
}

- (void)setHidesNavigationBarDuringPresentation:(BOOL)hidesNavigationBarDuringPresentation {
if (self.searchController) {
self.searchController.hidesNavigationBarDuringPresentation = hidesNavigationBarDuringPresentation;
} else {
NSLog(@"%s 仅支持 iOS 8 及以上版本", __func__);
}
}

#pragma mark - QMUIEmptyView

- (void)showEmptyView {
Expand Down
16 changes: 4 additions & 12 deletions QMUIKit/UIKitExtensions/QMUITextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,19 @@
/**
* 自定义 UITextView,提供的特性如下:
*
* 1. 支持给输入框的文字设置加粗,倾斜,下划线等富文本样式。
* 2. 支持 placeholder 并支持更改 placeholderColor;若使用了富文本文字,则 placeholder 的样式也会跟随文字的样式(除了 placeholder 颜色)
* 3. 支持在文字发生变化时计算内容高度并通知 delegate (需打开autoResizable属性)。
* 4. 支持限制输入的文本的最大长度,默认不限制。
* 5. 修复了 iOS7 及以后的版本,系统的 UITextView 在输入最后一行文本时光标跑出可视区域的bug。
* 1. 支持 placeholder 并支持更改 placeholderColor;若使用了富文本文字,则 placeholder 的样式也会跟随文字的样式(除了 placeholder 颜色)
* 2. 支持在文字发生变化时计算内容高度并通知 delegate (需打开 autoResizable 属性)。
* 3. 支持限制输入的文本的最大长度,默认不限制。
* 4. 修正系统 UITextView 在输入时自然换行的时候,contentOffset 的滚动位置没有考虑 textContainerInset.bottom
*/
@interface QMUITextView : UITextView<QMUITextViewDelegate>

@property(nonatomic, weak) id<QMUITextViewDelegate> delegate;

/**
* 输入框的文本样式,默认为nil。注意当使用了这个属性后,不要再使用 `setAttributedText:` 方法。
*/
@property(nonatomic, copy) NSDictionary<NSString *, id> *textAttributes;

/**
* 当通过 `setText:`、`setAttributedText:`等方式修改文字时,是否应该自动触发 `UITextViewDelegate` 里的 `textView:shouldChangeTextInRange:replacementText:`、 `textViewDidChange:` 方法
*
* 默认为YES(注意系统的 UITextView 对这种行为默认是 NO)
*
* @see textAttributes
*/
@property(nonatomic, assign) IBInspectable BOOL shouldResponseToProgrammaticallyTextChanges;

Expand Down
Loading

0 comments on commit bc6aba1

Please sign in to comment.