Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for screen rotation issue #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions BouncyPresent/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14113" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="DiI-r2-A9v">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
<capability name="Alignment constraints with different attributes" minToolsVersion="5.1"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14283.14"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand All @@ -23,7 +22,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="vgx-ZB-gk6" customClass="PaddedButton" customModule="BouncyPresent" customModuleProvider="target">
<rect key="frame" x="105.5" y="353.5" width="165" height="48"/>
<rect key="frame" x="105" y="353.5" width="165" height="48"/>
<color key="backgroundColor" red="1" green="0.86195106580000003" blue="0.15694230179999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<fontDescription key="fontDescription" name="HelveticaNeue-Thin" family="Helvetica Neue" pointSize="22"/>
<state key="normal" title="Bouncy Present">
Expand Down Expand Up @@ -53,10 +52,11 @@
<constraint firstItem="QBT-9x-GXJ" firstAttribute="centerX" secondItem="vgx-ZB-gk6" secondAttribute="centerX" id="mDQ-GV-4yC"/>
</constraints>
</view>
<navigationItem key="navigationItem" id="623-m1-1yx"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="136" y="136"/>
<point key="canvasLocation" x="1074.4000000000001" y="135.38230884557723"/>
</scene>
<!--Overlay View Controller-->
<scene sceneID="xfq-Ck-ZZV">
Expand Down Expand Up @@ -97,7 +97,25 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iri-wH-kqe" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="883" y="136"/>
<point key="canvasLocation" x="1821.5999999999999" y="135.38230884557723"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="0hF-fn-IOI">
<objects>
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="DiI-r2-A9v" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="GRF-0G-dBA">
<rect key="frame" x="0.0" y="20" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
<connections>
<segue destination="BYZ-38-t0r" kind="relationship" relationship="rootViewController" id="A6q-Mm-aHc"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="rxW-Vv-SZs" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="327" y="135"/>
</scene>
</scenes>
</document>
6 changes: 6 additions & 0 deletions BouncyPresent/OverlayPresentationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ class OverlayPresentationController: UIPresentationController {
override func dismissalTransitionWillBegin() {
presentedViewController.transitionCoordinator?.animate(alongsideTransition: { _ in
self.dimmingView.alpha = 0.0

// This is a workaround for the bug(?) in UIPresentationController on iOS11 + iOS12
// whereby the frame of presentingViewController gets corrupted after screen rotation
self.presentingViewController.view.frame = CGRect(x: 0.0, y: 0.0,
width: UIScreen.main.bounds.size.width,
height: UIScreen.main.bounds.size.height)
}) { _ in
self.dimmingView.removeFromSuperview()
}
Expand Down
4 changes: 3 additions & 1 deletion BouncyPresent/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class ViewController: UIViewController {
}

@IBAction func handleBouncyPresentPressed(sender: AnyObject) {
let overlayViewController = storyboard?.instantiateViewController(withIdentifier: "overlayViewController") as! UIViewController
guard let overlayViewController = storyboard?.instantiateViewController(withIdentifier: "overlayViewController") else {
fatalError("Unable to instantiate ViewController with identifier 'overlayViewController'")
}
prepareOverlay(viewController: overlayViewController)
present(overlayViewController, animated: true)
}
Expand Down