Skip to content

Commit 1c0018a

Browse files
committed
[iOS Example] Fix layout issues
Replaced `[email protected]` with a `LaunchScreen.storyboard`. This allows the app to launch at native resolutions on newer devices. Pixels no longer scaled and blurry. Updated the UI to stack a `UITextView` and `UITextField` in a `UIStackView`. Added outlet to autolayout constrait, which gets modified when keyboard appears. The text field is now visible when the keyboard appears. Removed iPad-specific storyboard. This is no longer needed. Autolayout takes care of all of it.
1 parent 04548f3 commit 1c0018a

9 files changed

+126
-165
lines changed
-10.8 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
3+
<dependencies>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
5+
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
6+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
7+
</dependencies>
8+
<scenes>
9+
<!--View Controller-->
10+
<scene sceneID="EHf-IW-A2E">
11+
<objects>
12+
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
13+
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
14+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
15+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
16+
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
17+
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
18+
</view>
19+
</viewController>
20+
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
21+
</objects>
22+
<point key="canvasLocation" x="53" y="375"/>
23+
</scene>
24+
</scenes>
25+
</document>

Peertalk iOS Example/Main.storyboard

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17700" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="XoD-EK-7mu">
3+
<device id="retina4_7" orientation="portrait" appearance="light"/>
4+
<dependencies>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17703"/>
6+
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
7+
<capability name="System colors in document resources" minToolsVersion="11.0"/>
8+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
9+
</dependencies>
10+
<scenes>
11+
<!--View Controller-->
12+
<scene sceneID="yKR-st-fBH">
13+
<objects>
14+
<viewController id="XoD-EK-7mu" customClass="PTViewController" sceneMemberID="viewController">
15+
<view key="view" contentMode="scaleToFill" id="ZpS-WX-lBQ">
16+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
17+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
18+
<subviews>
19+
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="Lwc-Od-25m">
20+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
21+
<subviews>
22+
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="sn7-Se-ayI">
23+
<rect key="frame" x="0.0" y="0.0" width="375" height="633"/>
24+
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
25+
<color key="textColor" systemColor="labelColor"/>
26+
<fontDescription key="fontDescription" type="system" pointSize="14"/>
27+
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
28+
</textView>
29+
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="sDG-vC-Idt">
30+
<rect key="frame" x="0.0" y="633" width="375" height="34"/>
31+
<fontDescription key="fontDescription" type="system" pointSize="14"/>
32+
<textInputTraits key="textInputTraits"/>
33+
<connections>
34+
<outlet property="delegate" destination="XoD-EK-7mu" id="Iym-k3-nw2"/>
35+
</connections>
36+
</textField>
37+
</subviews>
38+
</stackView>
39+
</subviews>
40+
<viewLayoutGuide key="safeArea" id="H3d-So-F21"/>
41+
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
42+
<constraints>
43+
<constraint firstItem="Lwc-Od-25m" firstAttribute="top" secondItem="H3d-So-F21" secondAttribute="top" id="2Cb-dL-wmr"/>
44+
<constraint firstItem="Lwc-Od-25m" firstAttribute="trailing" secondItem="H3d-So-F21" secondAttribute="trailing" id="CiZ-R3-EKm"/>
45+
<constraint firstItem="Lwc-Od-25m" firstAttribute="bottom" secondItem="H3d-So-F21" secondAttribute="bottom" id="MpS-3H-aO4"/>
46+
<constraint firstItem="Lwc-Od-25m" firstAttribute="leading" secondItem="H3d-So-F21" secondAttribute="leading" id="SUl-yw-6Ds"/>
47+
</constraints>
48+
</view>
49+
<connections>
50+
<outlet property="bottomConstraint" destination="MpS-3H-aO4" id="8bh-Pz-OTa"/>
51+
<outlet property="inputTextField" destination="sDG-vC-Idt" id="ESd-nE-inH"/>
52+
<outlet property="outputTextView" destination="sn7-Se-ayI" id="gpK-xr-WO0"/>
53+
<outlet property="stackView" destination="Lwc-Od-25m" id="UqS-jm-cOb"/>
54+
<outlet property="view" destination="ZpS-WX-lBQ" id="BJY-eX-gL1"/>
55+
</connections>
56+
</viewController>
57+
<placeholder placeholderIdentifier="IBFirstResponder" id="xew-Tq-f0z" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
58+
</objects>
59+
<point key="canvasLocation" x="139" y="138"/>
60+
</scene>
61+
</scenes>
62+
<resources>
63+
<systemColor name="labelColor">
64+
<color white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
65+
</systemColor>
66+
<systemColor name="systemBackgroundColor">
67+
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
68+
</systemColor>
69+
</resources>
70+
</document>

Peertalk iOS Example/PTViewController.h

-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,4 @@
33

44
@interface PTViewController : UIViewController <PTChannelDelegate, UITextFieldDelegate>
55

6-
@property (weak) IBOutlet UITextView *outputTextView;
7-
@property (weak) IBOutlet UITextField *inputTextField;
8-
9-
- (void)sendMessage:(NSString*)message;
10-
116
@end

Peertalk iOS Example/PTViewController.m

+20-12
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,26 @@ @interface PTViewController () {
55
__weak PTChannel *serverChannel_;
66
__weak PTChannel *peerChannel_;
77
}
8-
- (void)appendOutputMessage:(NSString*)message;
9-
- (void)sendDeviceInfo;
8+
@property (nonatomic) IBOutlet UIStackView *stackView;
9+
@property (nonatomic) IBOutlet UITextView *outputTextView;
10+
@property (nonatomic) IBOutlet UITextField *inputTextField;
11+
@property (nonatomic) IBOutlet NSLayoutConstraint *bottomConstraint;
1012
@end
1113

1214
@implementation PTViewController
1315

16+
@synthesize stackView = stackView_;
17+
@synthesize bottomConstraint = bottomConstraint_;
1418
@synthesize outputTextView = outputTextView_;
1519
@synthesize inputTextField = inputTextField_;
1620

1721
- (void)viewDidLoad {
1822
[super viewDidLoad];
19-
23+
24+
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
25+
2026
// Setup UI
21-
inputTextField_.delegate = self;
22-
inputTextField_.enablesReturnKeyAutomatically = NO;
2327
[inputTextField_ becomeFirstResponder];
24-
outputTextView_.text = @"";
2528

2629
// Create a new channel that is listening on our IPv4 port
2730
PTChannel *channel = [PTChannel channelWithDelegate:self];
@@ -35,14 +38,19 @@ - (void)viewDidLoad {
3538
}];
3639
}
3740

41+
- (void)keyboardWillShow:(NSNotification *)notification {
42+
CGRect keybordEndFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
43+
bottomConstraint_.constant = -keybordEndFrame.size.height;
44+
}
45+
3846
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
3947
return UIInterfaceOrientationMaskPortrait;
4048
}
4149

4250
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
4351
if (peerChannel_) {
44-
[self sendMessage:self.inputTextField.text];
45-
self.inputTextField.text = @"";
52+
[self sendMessage:inputTextField_.text];
53+
inputTextField_.text = @"";
4654
return NO;
4755
} else {
4856
return YES;
@@ -65,12 +73,12 @@ - (void)sendMessage:(NSString*)message {
6573

6674
- (void)appendOutputMessage:(NSString*)message {
6775
NSLog(@">> %@", message);
68-
NSString *text = self.outputTextView.text;
76+
NSString *text = outputTextView_.text;
6977
if (text.length == 0) {
70-
self.outputTextView.text = [text stringByAppendingString:message];
78+
outputTextView_.text = [text stringByAppendingString:message];
7179
} else {
72-
self.outputTextView.text = [text stringByAppendingFormat:@"\n%@", message];
73-
[self.outputTextView scrollRangeToVisible:NSMakeRange(self.outputTextView.text.length, 0)];
80+
outputTextView_.text = [text stringByAppendingFormat:@"\n%@", message];
81+
[outputTextView_ scrollRangeToVisible:NSMakeRange(outputTextView_.text.length, 0)];
7482
}
7583
}
7684

Peertalk iOS Example/Peertalk iOS Example-Info.plist

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@
3838
<string>1.0</string>
3939
<key>LSRequiresIPhoneOS</key>
4040
<true/>
41+
<key>UILaunchStoryboardName</key>
42+
<string>LaunchScreen</string>
4143
<key>UIMainStoryboardFile</key>
42-
<string>MainStoryboard_iPhone</string>
44+
<string>Main</string>
4345
<key>UIMainStoryboardFile~ipad</key>
4446
<string>MainStoryboard_iPad</string>
4547
<key>UIRequiredDeviceCapabilities</key>

Peertalk iOS Example/en.lproj/MainStoryboard_iPad.storyboard

-63
This file was deleted.

0 commit comments

Comments
 (0)