Merge pull request #1947 from keymanapp/ios-toggle-constraints

[iOS] UI Toggle Constraints
This commit is contained in:
Joshua Horton 2019-08-09 07:27:08 +07:00 • committed by GitHub
commit 64d41f7670
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 30 deletions

View file

@ -122,19 +122,33 @@ class LanguageSettingsViewController: UITableViewController {
if 0 == indexPath.row {
cell.accessoryType = .none
let doPredictionsSwitch = UISwitch()
doPredictionsSwitch.translatesAutoresizingMaskIntoConstraints = false
let switchFrame = frameAtRightOfCell(cell: cell.frame, controlSize: doPredictionsSwitch.frame.size)
doPredictionsSwitch.frame = switchFrame
doPredictionsSwitch.isOn = userDefaults.predictSettingForLanguage(languageID: self.language.id)
doPredictionsSwitch.addTarget(self, action: #selector(self.predictionSwitchValueChanged), for: .valueChanged)
cell.addSubview(doPredictionsSwitch)
if #available(iOSApplicationExtension 9.0, *) {
doPredictionsSwitch.rightAnchor.constraint(equalTo: cell.layoutMarginsGuide.rightAnchor).isActive = true
doPredictionsSwitch.centerYAnchor.constraint(equalTo: cell.layoutMarginsGuide.centerYAnchor).isActive = true
}
} else if 1 == indexPath.row {
cell.accessoryType = .none
let doCorrectionsSwitch = UISwitch()
doCorrectionsSwitch.translatesAutoresizingMaskIntoConstraints = false
let switchFrame = frameAtRightOfCell(cell: cell.frame, controlSize: doCorrectionsSwitch.frame.size)
doCorrectionsSwitch.frame = switchFrame
doCorrectionsSwitch.isOn = userDefaults.correctSettingForLanguage(languageID: self.language.id)
doCorrectionsSwitch.addTarget(self, action: #selector(self.correctionSwitchValueChanged), for: .valueChanged)
cell.addSubview(doCorrectionsSwitch)
if #available(iOSApplicationExtension 9.0, *) {
doCorrectionsSwitch.rightAnchor.constraint(equalTo: cell.layoutMarginsGuide.rightAnchor).isActive = true
doCorrectionsSwitch.centerYAnchor.constraint(equalTo: cell.layoutMarginsGuide.centerYAnchor).isActive = true
}
} else { // rows 3 and 4
cell.accessoryType = .disclosureIndicator
}

View file

@ -1,10 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<device id="retina5_5" orientation="landscape">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
@ -14,19 +13,19 @@
<objects>
<tableViewController id="TZd-6d-oTq" customClass="SettingsViewController" customModule="KeymanEngine" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" allowsSelection="NO" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="mfL-xR-a5l">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<rect key="frame" x="0.0" y="0.0" width="736" height="414"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" restorationIdentifier="languages" preservesSuperviewLayoutMargins="YES" selectionStyle="none" accessoryType="disclosureIndicator" indentationWidth="10" reuseIdentifier="languages" textLabel="D3M-Jf-Lhg" style="IBUITableViewCellStyleDefault" id="ebU-bs-BGU" userLabel="Languages">
<rect key="frame" x="0.0" y="28" width="375" height="44"/>
<rect key="frame" x="0.0" y="28" width="736" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="ebU-bs-BGU" id="ckE-eL-A5F">
<rect key="frame" x="0.0" y="0.0" width="341" height="43.5"/>
<rect key="frame" x="0.0" y="0.0" width="698" height="43.666666666666664"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Installed Languages..." textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="D3M-Jf-Lhg">
<rect key="frame" x="16" y="0.0" width="324" height="43.5"/>
<rect key="frame" x="20" y="0.0" width="678" height="43.666666666666664"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
@ -36,10 +35,10 @@
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" restorationIdentifier="showbanner" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="showbanner" id="qXA-sF-V3I" userLabel="Show Banner">
<rect key="frame" x="0.0" y="72" width="375" height="44"/>
<rect key="frame" x="0.0" y="72" width="736" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="qXA-sF-V3I" id="eRJ-8o-lZq">
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
<rect key="frame" x="0.0" y="0.0" width="736" height="43.666666666666664"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Show Banner" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="hOh-Ke-SIE">
@ -49,18 +48,20 @@
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="JGV-aw-EHN">
<rect key="frame" x="299" y="6" width="49" height="31"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" ambiguous="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="JGV-aw-EHN">
<rect key="frame" x="667" y="6" width="51" height="31"/>
</switch>
</subviews>
<constraints>
<constraint firstAttribute="trailingMargin" secondItem="JGV-aw-EHN" secondAttribute="trailing" id="mF1-1U-ehH"/>
</constraints>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" restorationIdentifier="getstarted" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="showgetstarted" id="TRl-40-iBT" userLabel="Show Get Started">
<rect key="frame" x="0.0" y="116" width="375" height="44"/>
<rect key="frame" x="0.0" y="116" width="736" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="TRl-40-iBT" id="uo0-bk-fdu">
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
<rect key="frame" x="0.0" y="0.0" width="736" height="43.666666666666664"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Show &quot;Get Started&quot; on startup" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="taa-7T-GwB">
@ -70,11 +71,13 @@
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="KSR-uB-Zv4">
<rect key="frame" x="299" y="6" width="49" height="31"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" ambiguous="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="KSR-uB-Zv4">
<rect key="frame" x="667" y="6" width="51" height="31"/>
</switch>
</subviews>
<constraints>
<constraint firstAttribute="trailingMargin" secondItem="KSR-uB-Zv4" secondAttribute="trailing" id="Czm-Ey-nqy"/>
</constraints>
</tableViewCellContentView>
</tableViewCell>
</prototypes>
@ -94,7 +97,7 @@
<objects>
<navigationController id="ywo-q8-YG6" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="Z19-HK-IbM">
<rect key="frame" x="0.0" y="20" width="375" height="44"/>
<rect key="frame" x="0.0" y="0.0" width="736" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>

View file

@ -118,34 +118,37 @@ open class SettingsViewController: UITableViewController {
case "showbanner":
cell.accessoryType = .none
let showBannerSwitch = UISwitch()
showBannerSwitch.translatesAutoresizingMaskIntoConstraints = false
let switchFrame = frameAtRightOfCell(cell: cell.frame, controlSize: showBannerSwitch.frame.size)
showBannerSwitch.frame = switchFrame
showBannerSwitch.isOn = false //TODO: find the setting this is to show!
showBannerSwitch.addTarget(self, action: #selector(self.bannerSwitchValueChanged),
for: .valueChanged)
cell.addSubview(showBannerSwitch)
if #available(iOSApplicationExtension 9.0, *) {
showBannerSwitch.rightAnchor.constraint(equalTo: cell.layoutMarginsGuide.rightAnchor).isActive = true
showBannerSwitch.centerYAnchor.constraint(equalTo: cell.layoutMarginsGuide.centerYAnchor).isActive = true
}
case "showgetstarted":
cell.accessoryType = .none
let dontShowAgainSwitch = UISwitch()
// let rightOffset = cell.frame.size.width
// let switchWidth: CGFloat = 20
// let switchX = rightOffset - switchWidth
// let dontShowAgainSwitch = UISwitch()
// let switchHeight = dontShowAgainSwitch.frame.size.height
// let cellSwitchHeightDiff = cell.frame.size.height - switchHeight
// let switchY = cell.frame.origin.y + 0.5 * cellSwitchHeightDiff
// let switchFrame = CGRect(x: switchX,
// y: switchY,
// width: switchWidth,
// height: cell.frame.size.height)
dontShowAgainSwitch.translatesAutoresizingMaskIntoConstraints = false
let switchFrame = frameAtRightOfCell(cell: cell.frame, controlSize: dontShowAgainSwitch.frame.size)
dontShowAgainSwitch.frame = switchFrame
dontShowAgainSwitch.isOn = dontShowGetStarted
dontShowAgainSwitch.addTarget(self, action: #selector(self.showGetStartedSwitchValueChanged),
for: .valueChanged)
cell.addSubview(dontShowAgainSwitch)
if #available(iOSApplicationExtension 9.0, *) {
dontShowAgainSwitch.rightAnchor.constraint(equalTo: cell.layoutMarginsGuide.rightAnchor).isActive = true
dontShowAgainSwitch.centerYAnchor.constraint(equalTo: cell.layoutMarginsGuide.centerYAnchor).isActive = true
}
default:
log.error("unknown cellIdentifier(\"\(cellIdentifier ?? "EMPTY")\")")
cell.accessoryType = .none

View file

@ -3,6 +3,9 @@
## 13.0 alpha
* Start version 13.0
## 2019-08-08 12.0.12 beta
* Fixes toggle alignment issues in the Settings UI (#1947)
## 2019-07-29 12.0.11 beta
* Initial beta release of Keyman for iPhone and iPad 12
* [Pull Requests](https://github.com/keymanapp/keyman/pulls?utf8=%E2%9C%93&q=is%3Apr+merged%3A2019-02-25..2019-08-04+label%3Aios+base%3Amaster)