diff --git a/LifeLog/LifeLog.xcodeproj/project.pbxproj b/LifeLog/LifeLog.xcodeproj/project.pbxproj index 760e965..db29ef1 100644 --- a/LifeLog/LifeLog.xcodeproj/project.pbxproj +++ b/LifeLog/LifeLog.xcodeproj/project.pbxproj @@ -13,6 +13,10 @@ 6E18CED81F2E3C840029891F /* ServerAPI.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E18CED71F2E3C840029891F /* ServerAPI.m */; }; 6E18CEDC1F2E40F50029891F /* User.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E18CEDB1F2E40F50029891F /* User.m */; }; 6E48AF0D1F2F9D3300C1D184 /* CustomTextField.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E48AF0C1F2F9D3200C1D184 /* CustomTextField.m */; }; + 6E7F93421F35872B00EFBC71 /* TPKeyboardAvoidingCollectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E7F933B1F35872B00EFBC71 /* TPKeyboardAvoidingCollectionView.m */; }; + 6E7F93431F35872B00EFBC71 /* TPKeyboardAvoidingScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E7F933D1F35872B00EFBC71 /* TPKeyboardAvoidingScrollView.m */; }; + 6E7F93441F35872B00EFBC71 /* TPKeyboardAvoidingTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E7F933F1F35872B00EFBC71 /* TPKeyboardAvoidingTableView.m */; }; + 6E7F93451F35872B00EFBC71 /* UIScrollView+TPKeyboardAvoidingAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E7F93411F35872B00EFBC71 /* UIScrollView+TPKeyboardAvoidingAdditions.m */; }; 6E84E3761F27A701001EB88E /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E84E3751F27A701001EB88E /* main.m */; }; 6E84E3791F27A701001EB88E /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E84E3781F27A701001EB88E /* AppDelegate.m */; }; 6E84E3811F27A701001EB88E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6E84E3801F27A701001EB88E /* Assets.xcassets */; }; @@ -73,6 +77,14 @@ 6E18CEDD1F2E46570029891F /* Entities.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Entities.h; sourceTree = ""; }; 6E48AF0B1F2F9D3200C1D184 /* CustomTextField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomTextField.h; sourceTree = ""; }; 6E48AF0C1F2F9D3200C1D184 /* CustomTextField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CustomTextField.m; sourceTree = ""; }; + 6E7F933A1F35872B00EFBC71 /* TPKeyboardAvoidingCollectionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TPKeyboardAvoidingCollectionView.h; sourceTree = ""; }; + 6E7F933B1F35872B00EFBC71 /* TPKeyboardAvoidingCollectionView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TPKeyboardAvoidingCollectionView.m; sourceTree = ""; }; + 6E7F933C1F35872B00EFBC71 /* TPKeyboardAvoidingScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TPKeyboardAvoidingScrollView.h; sourceTree = ""; }; + 6E7F933D1F35872B00EFBC71 /* TPKeyboardAvoidingScrollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TPKeyboardAvoidingScrollView.m; sourceTree = ""; }; + 6E7F933E1F35872B00EFBC71 /* TPKeyboardAvoidingTableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TPKeyboardAvoidingTableView.h; sourceTree = ""; }; + 6E7F933F1F35872B00EFBC71 /* TPKeyboardAvoidingTableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TPKeyboardAvoidingTableView.m; sourceTree = ""; }; + 6E7F93401F35872B00EFBC71 /* UIScrollView+TPKeyboardAvoidingAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIScrollView+TPKeyboardAvoidingAdditions.h"; sourceTree = ""; }; + 6E7F93411F35872B00EFBC71 /* UIScrollView+TPKeyboardAvoidingAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIScrollView+TPKeyboardAvoidingAdditions.m"; sourceTree = ""; }; 6E84E3711F27A700001EB88E /* LifeLog.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LifeLog.app; sourceTree = BUILT_PRODUCTS_DIR; }; 6E84E3751F27A701001EB88E /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 6E84E3771F27A701001EB88E /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; @@ -185,6 +197,21 @@ name = Model; sourceTree = ""; }; + 6E7F93391F35870F00EFBC71 /* TPKeyboardAvoiding */ = { + isa = PBXGroup; + children = ( + 6E7F933A1F35872B00EFBC71 /* TPKeyboardAvoidingCollectionView.h */, + 6E7F933B1F35872B00EFBC71 /* TPKeyboardAvoidingCollectionView.m */, + 6E7F933C1F35872B00EFBC71 /* TPKeyboardAvoidingScrollView.h */, + 6E7F933D1F35872B00EFBC71 /* TPKeyboardAvoidingScrollView.m */, + 6E7F933E1F35872B00EFBC71 /* TPKeyboardAvoidingTableView.h */, + 6E7F933F1F35872B00EFBC71 /* TPKeyboardAvoidingTableView.m */, + 6E7F93401F35872B00EFBC71 /* UIScrollView+TPKeyboardAvoidingAdditions.h */, + 6E7F93411F35872B00EFBC71 /* UIScrollView+TPKeyboardAvoidingAdditions.m */, + ); + name = TPKeyboardAvoiding; + sourceTree = ""; + }; 6E84E3681F27A700001EB88E = { isa = PBXGroup; children = ( @@ -339,6 +366,7 @@ 6ECC406D1F2A5FA500AAEB97 /* Library */ = { isa = PBXGroup; children = ( + 6E7F93391F35870F00EFBC71 /* TPKeyboardAvoiding */, 6ECC406E1F2A5FB200AAEB97 /* Category */, ); name = Library; @@ -599,12 +627,16 @@ buildActionMask = 2147483647; files = ( 6E18CED81F2E3C840029891F /* ServerAPI.m in Sources */, + 6E7F93431F35872B00EFBC71 /* TPKeyboardAvoidingScrollView.m in Sources */, + 6E7F93421F35872B00EFBC71 /* TPKeyboardAvoidingCollectionView.m in Sources */, 9CBDA0FA1F2ECE2C0055DED1 /* BaseViewController.m in Sources */, 6E8DA0F71F2BAC3400CCE941 /* TodayViewController.m in Sources */, + 6E7F93451F35872B00EFBC71 /* UIScrollView+TPKeyboardAvoidingAdditions.m in Sources */, 6E48AF0D1F2F9D3300C1D184 /* CustomTextField.m in Sources */, 6E84E3B01F27A975001EB88E /* HomeViewController.m in Sources */, 6E84E3791F27A701001EB88E /* AppDelegate.m in Sources */, 6E84E3BA1F27A9A0001EB88E /* RankingViewController.m in Sources */, + 6E7F93441F35872B00EFBC71 /* TPKeyboardAvoidingTableView.m in Sources */, 6EDC8BF41F2C68D700765ACC /* CMMotionActivityExtra.m in Sources */, 9CBDA0FF1F2F03810055DED1 /* RegisterViewController.m in Sources */, 9CA8AEEA1F31BB4600C5FC74 /* ConfirmForgetPassViewController.m in Sources */, @@ -768,6 +800,7 @@ "-framework", "\"CircleProgressBar\"", "-all_load", + "-ObjC", ); PRODUCT_BUNDLE_IDENTIFIER = mobileworld.jp.lifelog; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -791,6 +824,7 @@ "-framework", "\"CircleProgressBar\"", "-all_load", + "-ObjC", ); PRODUCT_BUNDLE_IDENTIFIER = mobileworld.jp.lifelog; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/LifeLog/LifeLog/BaseViewController.h b/LifeLog/LifeLog/BaseViewController.h index 374662b..d63ce4f 100644 --- a/LifeLog/LifeLog/BaseViewController.h +++ b/LifeLog/LifeLog/BaseViewController.h @@ -7,7 +7,11 @@ // #import +#import "TPKeyboardAvoidingCollectionView.h" +#import "TPKeyboardAvoidingScrollView.h" +#import "TPKeyboardAvoidingTableView.h" +#import "UIScrollView+TPKeyboardAvoidingAdditions.h" @interface BaseViewController : UIViewController -@property (nonatomic, weak) IBOutlet UIScrollView *scrollView; +@property (nonatomic, weak) IBOutlet TPKeyboardAvoidingScrollView *scrollView; @end diff --git a/LifeLog/LifeLog/BaseViewController.m b/LifeLog/LifeLog/BaseViewController.m index 6b9be85..87373ca 100644 --- a/LifeLog/LifeLog/BaseViewController.m +++ b/LifeLog/LifeLog/BaseViewController.m @@ -16,17 +16,7 @@ - (void)viewDidLoad { [super viewDidLoad]; - // Do any additional setup after loading the view. - NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; - [center addObserver:self - selector:@selector(keyboardWillShow:) - name:UIKeyboardWillShowNotification - object:nil]; - [center addObserver:self - selector:@selector(keyboardWillHide:) - name:UIKeyboardWillHideNotification - object:nil]; - // self.scrollView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag; + self.scrollView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag; } - (void)didReceiveMemoryWarning { @@ -34,74 +24,4 @@ // Dispose of any resources that can be recreated. } -#pragma mark - keyboard notifications - -- (void)keyboardWillShow:(NSNotification *)notification -{ - //Obtain Keyboard Position and Size Information - キーボードのポジション・サイズを取得 - CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; - - // Add the keyboard size to the bottom content inset of the scroll view. - // スクロールビューの底ContentInsetキーボードサイズを追加 - UIEdgeInsets inset = self.scrollView.contentInset; - inset.bottom = keyboardFrame.size.height; - self.scrollView.contentInset = inset; - - UIEdgeInsets scrollInset = self.scrollView.scrollIndicatorInsets; - scrollInset.bottom = keyboardFrame.size.height; - self.scrollView.scrollIndicatorInsets = scrollInset; - - //Obtain First Responder - FirstResponderを入手 - UIView *currentFirstResponder = [self _findFirstResponder:self.scrollView]; - CGRect rectResponder = currentFirstResponder.frame; - - // Determine visible frame - 表示なフレームを設定 - CGRect visibleFrame = self.view.frame; - visibleFrame.size.height -= keyboardFrame.size.height; - - // Determine whether item is in visible frame - アイテムを表示フレーム内にあるかどうかを確認 - if (!CGRectContainsPoint(visibleFrame, rectResponder.origin) ) - { - [UIView beginAnimations:nil context:NULL]; - [UIView setAnimationDuration:[notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]]; - [UIView setAnimationCurve:[notification.userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue]]; - [UIView setAnimationBeginsFromCurrentState:YES]; - int scrollPointY = (rectResponder.origin.y - keyboardFrame.origin.y) + rectResponder.size.height + 5; - //5 = minor padding - 5はマイナーパディング - CGPoint scrollPoint = CGPointMake(0.0, scrollPointY); - //Scroll to new point - 新ポイントにスクロール - [self.scrollView setContentOffset:scrollPoint animated:YES]; - [UIView commitAnimations]; - } -} - - -- (void)keyboardWillHide:(NSNotification *)notification -{ - [UIView beginAnimations:nil context:NULL]; - [UIView setAnimationDuration:[notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]]; - [UIView setAnimationCurve:[notification.userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue]]; - [UIView setAnimationBeginsFromCurrentState:YES]; - UIEdgeInsets inset = self.scrollView.contentInset; - inset.bottom = 0; - self.scrollView.contentInset = inset; - - UIEdgeInsets scrollInset = self.scrollView.scrollIndicatorInsets; - scrollInset.bottom = 0; - self.scrollView.scrollIndicatorInsets = scrollInset; - - [self.scrollView setContentOffset:CGPointMake(0, -self.scrollView.contentInset.top) animated:YES]; - [UIView commitAnimations]; -} - -- (UIView *)_findFirstResponder:(UIView *)view -{ - for ( UIView *childView in view.subviews ) { - if ( [childView respondsToSelector:@selector(isFirstResponder)] && [childView isFirstResponder] ) return childView; - UIView *result = [self _findFirstResponder:childView]; - if ( result ) return result; - } - return nil; -} - @end diff --git a/LifeLog/LifeLog/LoginViewController.m b/LifeLog/LifeLog/LoginViewController.m index 9187fb7..8ae8e3f 100644 --- a/LifeLog/LifeLog/LoginViewController.m +++ b/LifeLog/LifeLog/LoginViewController.m @@ -54,7 +54,42 @@ // Dispose of any resources that can be recreated. } +- (BOOL)checkAllowLogin +{ + NSString *message = @""; + if (_tfEmail.text.length <= 0) { + message = @"Please input email"; + [Utilities showErrorMessage:message withViewController:self]; + return NO; + } + if (_tfPassword.text.length <= 0) { + message = @"Please input password"; + [Utilities showErrorMessage:message withViewController:self]; + return NO; + } + if (_tfEmail.text.length > 255) { + message = @"Email maximum length 255"; + [Utilities showErrorMessage:message withViewController:self]; + return NO; + } + if (_tfPassword.text.length < 6) { + message = @"Password minimum length 6"; + [Utilities showErrorMessage:message withViewController:self]; + return NO; + } + if (![_tfEmail.text containsString:@"@"]) { + message = @"Email invalid"; + [Utilities showErrorMessage:message withViewController:self]; + return NO; + } + return YES; +} + - (IBAction)buttonLoginTouchUpInside:(id)sender { + [self resignTextField]; + if (![self checkAllowLogin]) { + return; + } LoginViewController __weak *weakSelf = self; [[ServerAPI server] loginWithEmail:_tfEmail.text Password:_tfPassword.text CompletionHandler:^(User *user, NSString *token, NSError *error) { if (error == nil) { @@ -78,6 +113,7 @@ } - (IBAction)buttonForgetTouchUpInside:(id)sender { + [self resignTextField]; if (_tfEmail.text.length > 0) { LoginViewController __weak *weakSelf = self; [[ServerAPI server] forgetPass:_tfEmail.text CompletionHandler:^(NSError *error) { @@ -103,8 +139,15 @@ } - (IBAction)buttonRegisterTouchUpInside:(id)sender { + [self resignTextField]; RegisterViewController *registerVC = [[RegisterViewController alloc] initWithNibName:@"RegisterViewController" bundle:nil]; [self.navigationController pushViewController:registerVC animated:YES]; } +- (void)resignTextField +{ + [_tfEmail resignFirstResponder]; + [_tfPassword resignFirstResponder]; +} + @end diff --git a/LifeLog/LifeLog/LoginViewController.xib b/LifeLog/LifeLog/LoginViewController.xib index 0287e7f..3589966 100644 --- a/LifeLog/LifeLog/LoginViewController.xib +++ b/LifeLog/LifeLog/LoginViewController.xib @@ -17,7 +17,7 @@ - + @@ -28,7 +28,7 @@ - + diff --git a/LifeLog/LifeLog/RegisterViewController.xib b/LifeLog/LifeLog/RegisterViewController.xib index 1ceaed2..908766c 100644 --- a/LifeLog/LifeLog/RegisterViewController.xib +++ b/LifeLog/LifeLog/RegisterViewController.xib @@ -1,10 +1,10 @@ - + - + @@ -31,7 +31,7 @@ - + @@ -54,7 +54,7 @@ - +