Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

Commit

Permalink
fix item size caculate wrong in formsheet
Browse files Browse the repository at this point in the history
  • Loading branch information
StormXX committed Nov 30, 2016
1 parent ff362cc commit 8d8258f
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 34 deletions.
Binary file not shown.
15 changes: 11 additions & 4 deletions PhotoPicker/AssetsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ class AssetsViewController: UICollectionViewController {
fileprivate var sendBarItem: UIBarButtonItem!
fileprivate var needHighQuality: Bool = false
fileprivate var selectedIndexPaths: [IndexPath] = []
fileprivate var isFirstLoading: Bool = true

override func viewDidLoad() {
super.viewDidLoad()


collectionView?.layoutIfNeeded()
view.layoutIfNeeded()
setupCancelButton()
setupToolBar()
resetCachedAssets()
Expand Down Expand Up @@ -75,6 +78,10 @@ class AssetsViewController: UICollectionViewController {

updateCachedAssets()
}

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
}

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
guard let collectionView = collectionView else { return }
Expand Down Expand Up @@ -514,9 +521,9 @@ extension AssetsViewController: UICollectionViewDelegateFlowLayout {
default:
numberOfColumns = AssetsNumberOfColumns.LandscapePhone
}
let width: CGFloat = floor((view.frame.width - 2.0 * CGFloat(numberOfColumns - 1)) / CGFloat(numberOfColumns))


let containerViewWidth = photoPickerController.view.frame.width
let width: CGFloat = floor((containerViewWidth - 2.0 * CGFloat(numberOfColumns - 1)) / CGFloat(numberOfColumns))
return CGSize(width: width, height: width)
}
}
Expand Down
49 changes: 26 additions & 23 deletions PhotoPicker/PhotoPicker.storyboard
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15G31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11542" systemVersion="15G1108" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11524"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Photos-->
<scene sceneID="bbg-5s-j6D">
<objects>
<tableViewController storyboardIdentifier="AlbumsViewController" id="4R6-ur-g33" customClass="AlbumsViewController" customModule="PhotoPicker" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="none" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" id="pv5-2y-vTQ">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="AlbumCell" rowHeight="86" id="Al7-0g-hnR" customClass="AlbumCell" customModule="PhotoPicker" customModuleProvider="target">
<rect key="frame" x="0.0" y="92" width="600" height="86"/>
<rect key="frame" x="0.0" y="28" width="375" height="86"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="Al7-0g-hnR" id="68r-9n-lV2">
<rect key="frame" x="0.0" y="0.0" width="600" height="86"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="86"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="t7m-Bv-r5d" userLabel="ImageContainerView">
Expand Down Expand Up @@ -47,7 +51,7 @@
</constraints>
</imageView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="gxs-S3-rj4" firstAttribute="centerX" secondItem="t7m-Bv-r5d" secondAttribute="centerX" id="2Kt-4q-Yq3"/>
<constraint firstItem="umb-hm-tLi" firstAttribute="centerX" secondItem="t7m-Bv-r5d" secondAttribute="centerX" id="Anb-R5-RVa"/>
Expand All @@ -59,16 +63,16 @@
<constraint firstItem="gxs-S3-rj4" firstAttribute="top" secondItem="t7m-Bv-r5d" secondAttribute="top" id="oZy-d9-eMK"/>
</constraints>
</view>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Album Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="GGe-yy-a7t" userLabel="titleLabel">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="Album Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="GGe-yy-a7t" userLabel="titleLabel">
<rect key="frame" x="102" y="22" width="490" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Number of Photos" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="2Bq-Md-A4T" userLabel="countLabel">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="Number of Photos" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="2Bq-Md-A4T" userLabel="countLabel">
<rect key="frame" x="102" y="45" width="490" height="14.5"/>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
Expand Down Expand Up @@ -109,9 +113,9 @@
<objects>
<collectionViewController id="ghK-eu-dfl" customClass="AssetsViewController" customModule="PhotoPicker" customModuleProvider="target" sceneMemberID="viewController">
<collectionView key="view" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" id="w8h-wI-TYC">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="2" minimumInteritemSpacing="2" id="7ql-hd-BIO">
<size key="itemSize" width="78" height="78"/>
<size key="headerReferenceSize" width="0.0" height="0.0"/>
Expand All @@ -120,7 +124,7 @@
</collectionViewFlowLayout>
<cells>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="AssetCell" id="6Ww-0p-UBG" customClass="AssetCell" customModule="PhotoPicker" customModuleProvider="target">
<rect key="frame" x="0.0" y="72" width="78" height="78"/>
<rect key="frame" x="0.0" y="8" width="78" height="78"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
<rect key="frame" x="0.0" y="0.0" width="78" height="78"/>
Expand All @@ -134,15 +138,15 @@
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="aUh-Z8-ChR" customClass="VideoIconView" customModule="PhotoPicker" customModuleProvider="target">
<rect key="frame" x="5" y="6" width="14" height="8"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="width" constant="14" id="YPM-Xw-fCT"/>
<constraint firstAttribute="height" constant="8" id="hDF-t0-vyO"/>
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="FFI-da-jA3" customClass="SlomoIconView" customModule="PhotoPicker" customModuleProvider="target">
<rect key="frame" x="5" y="3" width="12" height="12"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="12" id="46j-Qt-yK4"/>
<constraint firstAttribute="width" constant="12" id="xMT-zV-bGi"/>
Expand All @@ -151,11 +155,11 @@
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="00:00" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="VlG-ZK-GnM">
<rect key="frame" x="23" y="3.5" width="50" height="14.5"/>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="textColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="aUh-Z8-ChR" firstAttribute="centerY" secondItem="tEl-5f-9Sx" secondAttribute="centerY" id="0J4-9f-1Dm"/>
<constraint firstItem="aUh-Z8-ChR" firstAttribute="leading" secondItem="tEl-5f-9Sx" secondAttribute="leading" constant="5" id="0iL-Rk-qjX"/>
Expand Down Expand Up @@ -183,14 +187,13 @@
</constraints>
</imageView>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="trailing" secondItem="5Wg-fA-8qV" secondAttribute="trailing" constant="4" id="Ebx-iE-cM7"/>
<constraint firstItem="5Wg-fA-8qV" firstAttribute="top" secondItem="pNO-2d-B21" secondAttribute="top" constant="4" id="gGA-0L-ucx"/>
</constraints>
</view>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
</view>
<constraints>
<constraint firstItem="pNO-2d-B21" firstAttribute="leading" secondItem="6Ww-0p-UBG" secondAttribute="leading" id="8hO-sp-Vh1"/>
Expand All @@ -214,13 +217,13 @@
</collectionViewCell>
</cells>
<collectionReusableView key="sectionFooterView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="AssetFooterView" id="cXw-IQ-bRw">
<rect key="frame" x="0.0" y="152" width="600" height="50"/>
<rect key="frame" x="0.0" y="88" width="375" height="50"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" tag="100" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Number of Photos" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="EaV-Xo-DXo">
<label opaque="NO" userInteractionEnabled="NO" tag="100" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="Number of Photos" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="EaV-Xo-DXo">
<rect key="frame" x="8" y="15" width="584" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
Expand Down
2 changes: 1 addition & 1 deletion PhotoPicker/constant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct AssetsNumberOfColumns {
static let PortraitPhone: Int = 4
static let PortraitPad: Int = 5
static let LandscapePhone: Int = 6
static let LandscapePad: Int = 7
static let LandscapePad: Int = 6
}

var currentOrientation: PhotoPickerOrientation {
Expand Down
Loading

0 comments on commit 8d8258f

Please sign in to comment.