Skip to content

Commit

Permalink
feature: support iOS 13 present animation
Browse files Browse the repository at this point in the history
  • Loading branch information
suricforever committed Nov 27, 2019
1 parent 8be36ec commit b556353
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 18 deletions.
9 changes: 7 additions & 2 deletions DropdownMenu/DropdownMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,16 @@ open class DropdownMenu: UIView {
private let iPhoneXPortraitTopOffset: CGFloat = 88.0
private let portraitTopOffset: CGFloat = 64.0
private let landscapeTopOffset: CGFloat = 32.0

private var topLayoutConstraintConstant: CGFloat {
var offset: CGFloat = 0
if !navigationController.isNavigationBarHidden {
offset = navigationController.navigationBar.frame.height + navigationController.navigationBar.frame.origin.y
if let navigationBarWindow = navigationController.view.window {
let convertRect = navigationController.view.convert(navigationController.navigationBar.frame, to: navigationBarWindow)
offset = convertRect.height + convertRect.origin.y
} else {
offset = navigationController.navigationBar.frame.height + navigationController.navigationBar.frame.origin.y
}
}
return offset + topOffsetY
}
Expand Down Expand Up @@ -165,7 +171,6 @@ open class DropdownMenu: UIView {
}

@objc func updateForOrientationChange(_ nofication: Notification) {
print("UIApplicationWillChangeStatusBarOrientation")
if let oriention = (nofication as NSNotification).userInfo?[UIApplication.statusBarOrientationUserInfoKey] as? Int {
var topOffset: CGFloat
switch oriention {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
Expand Down Expand Up @@ -30,6 +40,16 @@
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29",
Expand Down Expand Up @@ -64,6 +84,11 @@
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
}
],
"info" : {
Expand Down
38 changes: 22 additions & 16 deletions DropdownMenuDemo/DropdownMenuDemo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11542" systemVersion="16B2555" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="bEP-BO-oRt">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15505" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="bEP-BO-oRt">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11524"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15510"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="DropdownMenuDemo" customModuleProvider="target" sceneMemberID="viewController">
<viewController storyboardIdentifier="ViewController" id="BYZ-38-t0r" customClass="ViewController" customModule="DropdownMenuDemo" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
Expand All @@ -23,54 +20,63 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="have sections" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="BzP-Ey-vYz">
<rect key="frame" x="138" y="160" width="100" height="20"/>
<rect key="frame" x="137.5" y="140" width="100" height="20"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="25g-q9-wVt">
<rect key="frame" x="163" y="188" width="51" height="31"/>
<rect key="frame" x="163" y="168" width="51" height="31"/>
<connections>
<action selector="sectionSwitchValueChanged:" destination="BYZ-38-t0r" eventType="valueChanged" id="yt0-i8-kxP"/>
</connections>
</switch>
<slider opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" minValue="0.0" maxValue="100" translatesAutoresizingMaskIntoConstraints="NO" id="PVH-7j-Yyz">
<rect key="frame" x="44" y="120" width="287" height="31"/>
<rect key="frame" x="44" y="100" width="287" height="31"/>
<connections>
<action selector="changeOffsetAction:" destination="BYZ-38-t0r" eventType="valueChanged" id="Qpj-wW-J0V"/>
</connections>
</slider>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="DropDownMenu Top Offset: 0" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Ymy-Wm-YFe">
<rect key="frame" x="85.5" y="82" width="204.5" height="18"/>
<rect key="frame" x="85.5" y="62" width="204" height="18"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="0" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="nuX-bM-BJi">
<rect key="frame" x="27.5" y="125" width="10.5" height="21"/>
<rect key="frame" x="27.5" y="105" width="10.5" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="100" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="UPa-at-gEy">
<rect key="frame" x="338" y="125" width="29" height="21"/>
<rect key="frame" x="338" y="105" width="29" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="dNE-bH-i5L">
<rect key="frame" x="131.5" y="318.5" width="112" height="30"/>
<state key="normal" title="Present New VC"/>
<connections>
<action selector="presentAction:" destination="BYZ-38-t0r" eventType="touchUpInside" id="X7w-rA-VlG"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="BzP-Ey-vYz" firstAttribute="top" secondItem="PVH-7j-Yyz" secondAttribute="bottom" constant="10" id="02R-Sd-K1e"/>
<constraint firstItem="PVH-7j-Yyz" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leadingMargin" constant="30" id="0Lu-c0-q3U"/>
<constraint firstItem="Ymy-Wm-YFe" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" constant="18" id="45G-S5-ZiT"/>
<constraint firstAttribute="trailingMargin" secondItem="PVH-7j-Yyz" secondAttribute="trailing" constant="30" id="4t7-hS-eoX"/>
<constraint firstItem="dNE-bH-i5L" firstAttribute="centerY" secondItem="8bC-Xf-vdC" secondAttribute="centerY" id="6P6-hj-hNa"/>
<constraint firstAttribute="trailing" secondItem="UPa-at-gEy" secondAttribute="trailing" constant="8" id="7wh-Fk-E7w"/>
<constraint firstItem="PVH-7j-Yyz" firstAttribute="leading" secondItem="nuX-bM-BJi" secondAttribute="trailing" constant="8" id="Oi0-1S-YG7"/>
<constraint firstItem="PVH-7j-Yyz" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="Q1c-nW-fIa"/>
<constraint firstItem="nuX-bM-BJi" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" constant="61" id="Yfw-xR-7zO"/>
<constraint firstItem="UPa-at-gEy" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" constant="61" id="Zxl-Jb-fWH"/>
<constraint firstItem="PVH-7j-Yyz" firstAttribute="top" secondItem="Ymy-Wm-YFe" secondAttribute="bottom" constant="20" id="cN4-3J-XBo"/>
<constraint firstItem="dNE-bH-i5L" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="fF6-gV-9gO"/>
<constraint firstItem="Ymy-Wm-YFe" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="n3a-uW-YJF"/>
<constraint firstItem="25g-q9-wVt" firstAttribute="centerX" secondItem="BzP-Ey-vYz" secondAttribute="centerX" id="uiI-Kb-AoW"/>
<constraint firstItem="25g-q9-wVt" firstAttribute="top" secondItem="BzP-Ey-vYz" secondAttribute="bottom" constant="8" id="y3J-U1-nOz"/>
Expand Down Expand Up @@ -106,7 +112,7 @@
<tabBarItem key="tabBarItem" systemItem="mostViewed" id="2Qg-IJ-NSJ"/>
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="Bav-Hk-j9K">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
Expand All @@ -131,7 +137,7 @@
<rect key="frame" x="0.0" y="28" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="0qN-ja-FGY" id="TCk-ux-5Dk">
<rect key="frame" x="0.0" y="0.0" width="375" height="43"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</tableViewCellContentView>
</tableViewCell>
Expand Down Expand Up @@ -173,7 +179,7 @@
<tabBarItem key="tabBarItem" systemItem="featured" id="ou2-cE-6o6"/>
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="LSv-v6-4TW">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
Expand Down
5 changes: 5 additions & 0 deletions DropdownMenuDemo/DropdownMenuDemo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ class ViewController: UIViewController {
@IBAction func sectionSwitchValueChanged(_ sender: AnyObject) {
showSection = sectionSwitch.isOn
}

@IBAction func presentAction(_ sender: Any) {
let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ViewController")
present(UINavigationController(rootViewController: vc), animated: true, completion: nil)
}
}

extension ViewController: DropdownMenuDelegate {
Expand Down

0 comments on commit b556353

Please sign in to comment.