Skip to content

Commit a1ec93d

Browse files
committed
手机号注册 - 进行到最后一步时,不允许滑动返回,并且点「返回」按钮时给出提示
1 parent 56679b7 commit a1ec93d

File tree

4 files changed

+123
-0
lines changed

4 files changed

+123
-0
lines changed

Coding_iOS.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
4E217F171A70EDC700F6DF88 /* SVWebViewControllerActivity.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E217F0B1A70EDC700F6DF88 /* SVWebViewControllerActivity.m */; };
121121
4E217F1A1A71007800F6DF88 /* SVWebViewController.strings in Resources */ = {isa = PBXBuildFile; fileRef = 4E217F1C1A71007800F6DF88 /* SVWebViewController.strings */; };
122122
4E24B2681B43D33F004D7989 /* ProjectToChooseListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E24B2671B43D33F004D7989 /* ProjectToChooseListViewController.m */; };
123+
4E25271A1C327FAE0032A7F4 /* UIViewController+BackButtonHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E2527191C327FAE0032A7F4 /* UIViewController+BackButtonHandler.m */; };
123124
4E2719B81AB02F31006AE214 /* NProjectViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E2719B71AB02F31006AE214 /* NProjectViewController.m */; };
124125
4E2719C71AB07ED6006AE214 /* dot_line@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4E2719C61AB07ED6006AE214 /* dot_line@2x.png */; };
125126
4E2906A21A403B7D008A5B97 /* FileDownloadView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E2906A11A403B7D008A5B97 /* FileDownloadView.m */; };
@@ -1205,6 +1206,8 @@
12051206
4E217F1D1A71007C00F6DF88 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/SVWebViewController.strings"; sourceTree = "<group>"; };
12061207
4E24B2661B43D33F004D7989 /* ProjectToChooseListViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProjectToChooseListViewController.h; sourceTree = "<group>"; };
12071208
4E24B2671B43D33F004D7989 /* ProjectToChooseListViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ProjectToChooseListViewController.m; sourceTree = "<group>"; };
1209+
4E2527181C327FAE0032A7F4 /* UIViewController+BackButtonHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIViewController+BackButtonHandler.h"; sourceTree = "<group>"; };
1210+
4E2527191C327FAE0032A7F4 /* UIViewController+BackButtonHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+BackButtonHandler.m"; sourceTree = "<group>"; };
12081211
4E2719B61AB02F31006AE214 /* NProjectViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NProjectViewController.h; sourceTree = "<group>"; };
12091212
4E2719B71AB02F31006AE214 /* NProjectViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NProjectViewController.m; sourceTree = "<group>"; };
12101213
4E2719C61AB07ED6006AE214 /* dot_line@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "dot_line@2x.png"; sourceTree = "<group>"; };
@@ -3517,6 +3520,8 @@
35173520
4E0BD8551B6C7DFD0061CAA6 /* UIView+Frame.m */,
35183521
D09AA5BE1BFDEDD1008CA9EB /* NSString+Attribute.h */,
35193522
D09AA5BF1BFDEDD1008CA9EB /* NSString+Attribute.m */,
3523+
4E2527181C327FAE0032A7F4 /* UIViewController+BackButtonHandler.h */,
3524+
4E2527191C327FAE0032A7F4 /* UIViewController+BackButtonHandler.m */,
35203525
);
35213526
path = OC_Category;
35223527
sourceTree = "<group>";
@@ -5917,6 +5922,7 @@
59175922
4EABD2541AD3CA7E005E515F /* UIMessageInputView.m in Sources */,
59185923
7EB02FE61B6D0F3E00D2166C /* AudioManager.m in Sources */,
59195924
4E72F82D1B144778001B6CE6 /* NSMutableString+Common.m in Sources */,
5925+
4E25271A1C327FAE0032A7F4 /* UIViewController+BackButtonHandler.m in Sources */,
59205926
4E4D6A791B1C6C7800FD2E49 /* MRPRDetailCell.m in Sources */,
59215927
8EF643CA19FF7E2900F7EEB0 /* TopicContentCell.m in Sources */,
59225928
4E0B9A371BAD377600D57D54 /* ForkTreeCell.m in Sources */,

Coding_iOS/Controllers/Login/RegisterViewController.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#import "WebViewController.h"
1717
#import "CannotLoginViewController.h"
1818
#import "EaseInputTipsView.h"
19+
#import "UIViewController+BackButtonHandler.h"
1920

2021
@interface RegisterViewController ()<UITableViewDataSource, UITableViewDelegate, TTTAttributedLabelDelegate>
2122
@property (nonatomic, assign) RegisterMethodType medthodType;
@@ -73,9 +74,21 @@ - (void)viewDidLoad
7374
self.myTableView.tableFooterView=[self customFooterView];
7475
[self configTopView];
7576
[self configBottomView];
77+
}
7678

79+
- (BOOL)navigationShouldPopOnBackButton{
80+
if (_medthodType == RegisterMethodPhone && _stepIndex >= 2 && _myRegister.password.length > 0) {//顺序来到的第二步,不允许直接返回
81+
[[UIActionSheet bk_actionSheetCustomWithTitle:@"完成激活后才能正常使用 Coding,是否返回?" buttonTitles:nil destructiveTitle:@"确认返回" cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
82+
if (index == 0) {
83+
[self.navigationController popViewControllerAnimated:YES];
84+
}
85+
}] showInView:self.view];
86+
return NO;
87+
}
88+
return YES;
7789
}
7890

91+
7992
- (void)refreshCaptchaNeeded{
8093
__weak typeof(self) weakSelf = self;
8194
[[Coding_NetAPIManager sharedManager] request_CaptchaNeededWithPath:@"api/captcha/register" andBlock:^(id data, NSError *error) {
@@ -95,11 +108,15 @@ - (void)viewWillAppear:(BOOL)animated{
95108
if (_medthodType == RegisterMethodEamil || _stepIndex == 1) {
96109
[self refreshCaptchaNeeded];
97110
}
111+
if (_medthodType == RegisterMethodPhone && _stepIndex >= 2 && _myRegister.password.length > 0) {//顺序来到的第二步,不允许直接返回
112+
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
113+
}
98114
}
99115

100116
- (void)viewWillDisappear:(BOOL)animated{
101117
[super viewWillDisappear:animated];
102118
[self.view endEditing:YES];
119+
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
103120
}
104121

105122
- (EaseInputTipsView *)inputTipsView{
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//
2+
// UIViewController+BackButtonHandler.h
3+
//
4+
// Created by Sergey Nikitenko on 10/1/13.
5+
// Copyright 2013 Sergey Nikitenko. All rights reserved.
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files (the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions:
13+
//
14+
// The above copyright notice and this permission notice shall be included in
15+
// all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
// THE SOFTWARE.
24+
//
25+
26+
#import <UIKit/UIKit.h>
27+
28+
@protocol BackButtonHandlerProtocol <NSObject>
29+
@optional
30+
// Override this method in UIViewController derived class to handle 'Back' button click
31+
-(BOOL)navigationShouldPopOnBackButton;
32+
@end
33+
34+
@interface UIViewController (BackButtonHandler) <BackButtonHandlerProtocol>
35+
36+
@end
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
//
2+
// UIViewController+BackButtonHandler.m
3+
//
4+
// Created by Sergey Nikitenko on 10/1/13.
5+
// Copyright 2013 Sergey Nikitenko. All rights reserved.
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files (the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions:
13+
//
14+
// The above copyright notice and this permission notice shall be included in
15+
// all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
// THE SOFTWARE.
24+
//
25+
26+
#import "UIViewController+BackButtonHandler.h"
27+
28+
@implementation UIViewController (BackButtonHandler)
29+
30+
@end
31+
32+
@implementation UINavigationController (ShouldPopOnBackButton)
33+
34+
- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item {
35+
36+
if([self.viewControllers count] < [navigationBar.items count]) {
37+
return YES;
38+
}
39+
40+
BOOL shouldPop = YES;
41+
UIViewController* vc = [self topViewController];
42+
if([vc respondsToSelector:@selector(navigationShouldPopOnBackButton)]) {
43+
shouldPop = [vc navigationShouldPopOnBackButton];
44+
}
45+
46+
if(shouldPop) {
47+
dispatch_async(dispatch_get_main_queue(), ^{
48+
[self popViewControllerAnimated:YES];
49+
});
50+
} else {
51+
// Workaround for iOS7.1. Thanks to @boliva - http://stackoverflow.com/posts/comments/34452906
52+
for(UIView *subview in [navigationBar subviews]) {
53+
if(subview.alpha < 1.) {
54+
[UIView animateWithDuration:.25 animations:^{
55+
subview.alpha = 1.;
56+
}];
57+
}
58+
}
59+
}
60+
61+
return NO;
62+
}
63+
64+
@end

0 commit comments

Comments
 (0)