aboutsummaryrefslogtreecommitdiffstats
path: root/iBean
diff options
context:
space:
mode:
authorEddie Ehlin <eddiex@eddiex.se>2013-01-08 22:07:41 +0100
committerEddie Ehlin <eddiex@eddiex.se>2013-01-08 22:07:41 +0100
commit93db1e2ce763e68dcbaa786991e2a554a50489db (patch)
treefac3b02c5791c51fc6718764dac9d70199ebb111 /iBean
parentb361a55094cb64149cb1543c0c76c99be00a3da3 (diff)
downloadiBean-93db1e2ce763e68dcbaa786991e2a554a50489db.tar.gz
iBean-93db1e2ce763e68dcbaa786991e2a554a50489db.zip
Added keyboard fix in BeanCollectionInfo view, so that it doesn't gets displayed over the textview.
Diffstat (limited to 'iBean')
-rw-r--r--iBean/iBean.xcodeproj/project.xcworkspace/xcuserdata/eddiex.xcuserdatad/UserInterfaceState.xcuserstatebin31984 -> 30104 bytes
-rw-r--r--iBean/iBean/BeanCollectionInfoViewController.h6
-rw-r--r--iBean/iBean/BeanCollectionInfoViewController.m48
-rw-r--r--iBean/iBean/iPhoneStoryboard.storyboard97
4 files changed, 112 insertions, 39 deletions
diff --git a/iBean/iBean.xcodeproj/project.xcworkspace/xcuserdata/eddiex.xcuserdatad/UserInterfaceState.xcuserstate b/iBean/iBean.xcodeproj/project.xcworkspace/xcuserdata/eddiex.xcuserdatad/UserInterfaceState.xcuserstate
index 7042894..a31d1c9 100644
--- a/iBean/iBean.xcodeproj/project.xcworkspace/xcuserdata/eddiex.xcuserdatad/UserInterfaceState.xcuserstate
+++ b/iBean/iBean.xcodeproj/project.xcworkspace/xcuserdata/eddiex.xcuserdatad/UserInterfaceState.xcuserstate
Binary files differ
diff --git a/iBean/iBean/BeanCollectionInfoViewController.h b/iBean/iBean/BeanCollectionInfoViewController.h
index 391869d..815a7b1 100644
--- a/iBean/iBean/BeanCollectionInfoViewController.h
+++ b/iBean/iBean/BeanCollectionInfoViewController.h
@@ -9,7 +9,7 @@
#import <UIKit/UIKit.h>
@class BeanCollection;
-@interface BeanCollectionInfoViewController : UIViewController <UITextFieldDelegate, UITextViewDelegate>
+@interface BeanCollectionInfoViewController : UIViewController <UITextFieldDelegate, UITextViewDelegate, UIScrollViewDelegate>
@property (nonatomic, strong) BeanCollection *beanCollection;
@property (nonatomic, assign) BOOL editMode;
@@ -22,11 +22,15 @@
/* UI Outlets */
@property (weak, nonatomic) IBOutlet UITextField *beanCollectionNameTextField;
@property (weak, nonatomic) IBOutlet UITextView *beanCollectionNoteTextView;
+@property (weak, nonatomic) IBOutlet UIScrollView *beanCollectionScrollView;
/* UI Actions */
- (IBAction) beanCollectioNameChanged;
- (IBAction) beanCollectionNoteChanged;
+- (IBAction) keyboardDisplayed:(NSNotification*)keyboardNotification;
+- (IBAction) keyboardHidden:(NSNotification*)keyboardNotification;
+
/* UITextFieldDelegate */
- (BOOL)textFieldShouldReturn:(UITextField *)textField;
diff --git a/iBean/iBean/BeanCollectionInfoViewController.m b/iBean/iBean/BeanCollectionInfoViewController.m
index a246b47..39a6422 100644
--- a/iBean/iBean/BeanCollectionInfoViewController.m
+++ b/iBean/iBean/BeanCollectionInfoViewController.m
@@ -35,6 +35,23 @@
{
[super viewWillAppear:animated];
[self initViewController];
+
+ //Register keyboard events
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(keyboardDisplayed:)
+ name:UIKeyboardDidShowNotification object:nil];
+
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(keyboardHidden:)
+ name:UIKeyboardWillHideNotification object:nil];
+}
+
+- (void) viewWillDisappear:(BOOL)animated
+{
+ [super viewWillDisappear:animated];
+
+ //Unregister keyboard events
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)didReceiveMemoryWarning
@@ -55,6 +72,7 @@
}
//Purpose: Hide keyboard when active control looses focus.
+/*
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
@@ -70,6 +88,7 @@
[super touchesBegan:touches withEvent:event];
}
+*/
/*****************************************************
Utility methods
@@ -120,6 +139,35 @@
}
}
+- (void) keyboardDisplayed:(NSNotification *)keyboardNotification
+{
+ //Make sure that beanCollectionTextView is accessable even with keyboard visible.
+ //See: https://developer.apple.com/library/ios/#documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html
+ NSDictionary* info = [keyboardNotification userInfo];
+ CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
+
+ UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
+ self.beanCollectionScrollView.contentInset = contentInsets;
+ self.beanCollectionScrollView.scrollIndicatorInsets = contentInsets;
+
+ // If active text field is hidden by keyboard, scroll it so it's visible
+ // Your application might not need or want this behavior.
+ /*
+ CGRect aRect = self.view.frame;
+ aRect.size.height -= kbSize.height;
+ if (!CGRectContainsPoint(aRect, self.beanCollectionNoteTextView.frame.origin) ) {
+ CGPoint scrollPoint = CGPointMake(0.0, self.beanCollectionNoteTextView.frame.origin.y-kbSize.height);
+ [self.beanCollectionScrollView setContentOffset:scrollPoint animated:YES];
+ }*/
+}
+
+- (void) keyboardHidden:(NSNotification *)keyboardNotification
+{
+ UIEdgeInsets contentInsets = UIEdgeInsetsZero;
+ self.beanCollectionScrollView.contentInset = contentInsets;
+ self.beanCollectionScrollView.scrollIndicatorInsets = contentInsets;
+}
+
/* UITextFieldDelegate */
#pragma mark - UITextFieldDelegate methods
diff --git a/iBean/iBean/iPhoneStoryboard.storyboard b/iBean/iBean/iPhoneStoryboard.storyboard
index 304377c..22197b1 100644
--- a/iBean/iBean/iPhoneStoryboard.storyboard
+++ b/iBean/iBean/iPhoneStoryboard.storyboard
@@ -170,49 +170,66 @@
<rect key="frame" x="0.0" y="64" width="320" height="504"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
- <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Bean collection name:" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="X5J-eE-KuX">
- <fontDescription key="fontDescription" type="system" pointSize="17"/>
- <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
- <nil key="highlightedColor"/>
- </label>
- <textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Enter a descriptive unique name here" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="Vla-ab-hH3">
- <fontDescription key="fontDescription" type="system" pointSize="14"/>
- <textInputTraits key="textInputTraits"/>
- <connections>
- <action selector="beanCollectioNameChanged" destination="5Zc-ii-ZPi" eventType="editingDidEnd" id="djb-Vf-Hjd"/>
- <outlet property="delegate" destination="5Zc-ii-ZPi" id="z1c-9h-NJ9"/>
- </connections>
- </textField>
- <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Notes:" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="HFn-UM-1hs">
- <fontDescription key="fontDescription" type="system" pointSize="17"/>
- <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
- <nil key="highlightedColor"/>
- </label>
- <textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" text="0.25dl milk (red)" translatesAutoresizingMaskIntoConstraints="NO" id="JHg-Fk-IL0">
- <color key="backgroundColor" red="0.6845703125" green="0.58594199899999999" blue="0.51132836960000005" alpha="1" colorSpace="calibratedRGB"/>
- <fontDescription key="fontDescription" type="system" pointSize="14"/>
- <textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
- <dataDetectorType key="dataDetectorTypes" link="YES"/>
+ <scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="gb9-GM-dee">
+ <subviews>
+ <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Bean collection name:" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="X5J-eE-KuX">
+ <fontDescription key="fontDescription" type="system" pointSize="17"/>
+ <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
+ <nil key="highlightedColor"/>
+ </label>
+ <textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Enter a descriptive unique name here" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="Vla-ab-hH3">
+ <fontDescription key="fontDescription" type="system" pointSize="14"/>
+ <textInputTraits key="textInputTraits" returnKeyType="done"/>
+ <connections>
+ <action selector="beanCollectioNameChanged" destination="5Zc-ii-ZPi" eventType="editingDidEnd" id="djb-Vf-Hjd"/>
+ <outlet property="delegate" destination="5Zc-ii-ZPi" id="z1c-9h-NJ9"/>
+ </connections>
+ </textField>
+ <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Notes:" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="HFn-UM-1hs">
+ <fontDescription key="fontDescription" type="system" pointSize="17"/>
+ <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
+ <nil key="highlightedColor"/>
+ </label>
+ <textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" text="0.25dl milk (red)" translatesAutoresizingMaskIntoConstraints="NO" id="JHg-Fk-IL0">
+ <color key="backgroundColor" red="0.6845703125" green="0.58594199899999999" blue="0.51132836960000005" alpha="1" colorSpace="calibratedRGB"/>
+ <constraints>
+ <constraint firstAttribute="height" constant="368" id="eyQ-2Q-yaW"/>
+ </constraints>
+ <fontDescription key="fontDescription" type="system" pointSize="14"/>
+ <textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
+ <dataDetectorType key="dataDetectorTypes" link="YES"/>
+ <connections>
+ <outlet property="delegate" destination="5Zc-ii-ZPi" id="0no-Ru-wVQ"/>
+ </connections>
+ </textView>
+ </subviews>
+ <constraints>
+ <constraint firstItem="JHg-Fk-IL0" firstAttribute="centerX" secondItem="gb9-GM-dee" secondAttribute="centerX" type="default" id="1lL-s7-sRw"/>
+ <constraint firstItem="X5J-eE-KuX" firstAttribute="leading" secondItem="gb9-GM-dee" secondAttribute="leading" constant="20" symbolic="YES" type="default" id="26U-lr-78J"/>
+ <constraint firstItem="X5J-eE-KuX" firstAttribute="top" secondItem="gb9-GM-dee" secondAttribute="top" constant="20" symbolic="YES" type="default" id="BvG-pg-Ome"/>
+ <constraint firstAttribute="bottom" secondItem="JHg-Fk-IL0" secondAttribute="bottom" constant="20" symbolic="YES" type="default" id="IFE-uf-7iS"/>
+ <constraint firstItem="JHg-Fk-IL0" firstAttribute="leading" secondItem="gb9-GM-dee" secondAttribute="leading" constant="20" symbolic="YES" type="default" id="JfD-PW-BjZ"/>
+ <constraint firstItem="HFn-UM-1hs" firstAttribute="top" secondItem="Vla-ab-hH3" secondAttribute="bottom" constant="8" symbolic="YES" type="default" id="Lcl-Wf-kfY"/>
+ <constraint firstAttribute="trailing" secondItem="Vla-ab-hH3" secondAttribute="trailing" constant="20" symbolic="YES" type="default" id="Vgq-bP-iLT"/>
+ <constraint firstAttribute="trailing" secondItem="X5J-eE-KuX" secondAttribute="trailing" constant="20" symbolic="YES" type="default" id="cjV-0g-YWu"/>
+ <constraint firstItem="JHg-Fk-IL0" firstAttribute="top" secondItem="HFn-UM-1hs" secondAttribute="bottom" constant="8" symbolic="YES" type="default" id="czz-nF-pd8"/>
+ <constraint firstItem="Vla-ab-hH3" firstAttribute="leading" secondItem="gb9-GM-dee" secondAttribute="leading" constant="20" symbolic="YES" type="default" id="iyC-ja-8lm"/>
+ <constraint firstAttribute="trailing" secondItem="HFn-UM-1hs" secondAttribute="trailing" constant="20" symbolic="YES" type="default" id="lpz-Su-Wdn"/>
+ <constraint firstItem="Vla-ab-hH3" firstAttribute="top" secondItem="X5J-eE-KuX" secondAttribute="bottom" constant="8" symbolic="YES" type="default" id="pAZ-qM-Sm7"/>
+ <constraint firstItem="HFn-UM-1hs" firstAttribute="leading" secondItem="gb9-GM-dee" secondAttribute="leading" constant="20" symbolic="YES" type="default" id="rRh-JP-w0C"/>
+ <constraint firstAttribute="trailing" secondItem="JHg-Fk-IL0" secondAttribute="trailing" constant="20" symbolic="YES" type="default" id="wAM-Qa-kBW"/>
+ </constraints>
<connections>
- <outlet property="delegate" destination="5Zc-ii-ZPi" id="0no-Ru-wVQ"/>
+ <outlet property="delegate" destination="5Zc-ii-ZPi" id="l3q-ZM-dx8"/>
</connections>
- </textView>
+ </scrollView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
- <constraint firstAttribute="trailing" secondItem="JHg-Fk-IL0" secondAttribute="trailing" constant="20" symbolic="YES" type="default" id="2fr-zF-6pL"/>
- <constraint firstAttribute="bottom" secondItem="JHg-Fk-IL0" secondAttribute="bottom" constant="20" symbolic="YES" type="default" id="397-DJ-gRl"/>
- <constraint firstItem="Vla-ab-hH3" firstAttribute="top" secondItem="X5J-eE-KuX" secondAttribute="bottom" constant="8" symbolic="YES" type="default" id="5J8-Ne-fpj"/>
- <constraint firstItem="HFn-UM-1hs" firstAttribute="top" secondItem="Vla-ab-hH3" secondAttribute="bottom" constant="8" symbolic="YES" type="default" id="Web-Sf-Oc0"/>
- <constraint firstAttribute="trailing" secondItem="Vla-ab-hH3" secondAttribute="trailing" constant="20" symbolic="YES" type="default" id="YDR-qg-128"/>
- <constraint firstItem="JHg-Fk-IL0" firstAttribute="leading" secondItem="clg-Db-36O" secondAttribute="leading" constant="20" symbolic="YES" type="default" id="cJm-Kv-XoV"/>
- <constraint firstItem="Vla-ab-hH3" firstAttribute="leading" secondItem="clg-Db-36O" secondAttribute="leading" constant="20" symbolic="YES" type="default" id="egB-MU-Pd7"/>
- <constraint firstAttribute="trailing" secondItem="X5J-eE-KuX" secondAttribute="trailing" constant="20" symbolic="YES" type="default" id="g6w-E3-8FE"/>
- <constraint firstItem="HFn-UM-1hs" firstAttribute="leading" secondItem="clg-Db-36O" secondAttribute="leading" constant="20" symbolic="YES" type="default" id="hEI-Yy-hJn"/>
- <constraint firstAttribute="trailing" secondItem="HFn-UM-1hs" secondAttribute="trailing" constant="20" symbolic="YES" type="default" id="mXY-BU-DsS"/>
- <constraint firstItem="X5J-eE-KuX" firstAttribute="top" secondItem="clg-Db-36O" secondAttribute="top" constant="20" symbolic="YES" type="default" id="sN2-9x-2su"/>
- <constraint firstItem="X5J-eE-KuX" firstAttribute="leading" secondItem="clg-Db-36O" secondAttribute="leading" constant="20" symbolic="YES" type="default" id="sk4-iU-NEc"/>
- <constraint firstItem="JHg-Fk-IL0" firstAttribute="top" secondItem="HFn-UM-1hs" secondAttribute="bottom" constant="8" symbolic="YES" type="default" id="viC-gO-ppl"/>
+ <constraint firstItem="gb9-GM-dee" firstAttribute="leading" secondItem="clg-Db-36O" secondAttribute="leading" type="default" id="9qK-8n-oWN"/>
+ <constraint firstItem="gb9-GM-dee" firstAttribute="top" secondItem="clg-Db-36O" secondAttribute="top" type="default" id="EW6-TS-V1S"/>
+ <constraint firstItem="gb9-GM-dee" firstAttribute="bottom" secondItem="clg-Db-36O" secondAttribute="bottom" type="default" id="NRs-w0-h70"/>
+ <constraint firstItem="gb9-GM-dee" firstAttribute="trailing" secondItem="clg-Db-36O" secondAttribute="trailing" type="default" id="yMX-ik-n76"/>
</constraints>
</view>
<navigationItem key="navigationItem" title="Information (1/3)" id="znt-MK-XJf">
@@ -230,6 +247,7 @@
<connections>
<outlet property="beanCollectionNameTextField" destination="Vla-ab-hH3" id="ZEz-IX-3Di"/>
<outlet property="beanCollectionNoteTextView" destination="JHg-Fk-IL0" id="48Y-nc-5uX"/>
+ <outlet property="beanCollectionScrollView" destination="gb9-GM-dee" id="jSv-s1-WgA"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="m7P-Kh-vW4" userLabel="First Responder" sceneMemberID="firstResponder"/>
@@ -460,8 +478,11 @@
<relationships>
<relationship kind="action" name="beanCollectioNameChanged"/>
<relationship kind="action" name="beanCollectionNoteChanged"/>
+ <relationship kind="action" name="keyboardDisplayed:" candidateClass="NSNotification"/>
+ <relationship kind="action" name="keyboardHidden:" candidateClass="NSNotification"/>
<relationship kind="outlet" name="beanCollectionNameTextField" candidateClass="UITextField"/>
<relationship kind="outlet" name="beanCollectionNoteTextView" candidateClass="UITextView"/>
+ <relationship kind="outlet" name="beanCollectionScrollView" candidateClass="UIScrollView"/>
</relationships>
</class>
<class className="BeanCollectionListViewController" superclassName="UITableViewController">