Skip to content

Commit

Permalink
Merge pull request #17 from nakajijapan/orientation
Browse files Browse the repository at this point in the history
Autorotation Problem
  • Loading branch information
nakajijapan committed Aug 1, 2015
2 parents df92ece + 1f911e2 commit 00d85a3
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 46 deletions.
6 changes: 3 additions & 3 deletions Example/PhotoSliderDemo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7706" systemVersion="14E33b" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="3DJ-Hp-ouc">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7706" systemVersion="14F6a" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="3DJ-Hp-ouc">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7703"/>
</dependencies>
Expand All @@ -16,7 +16,7 @@
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="356" sectionHeaderHeight="22" sectionFooterHeight="22" translatesAutoresizingMaskIntoConstraints="NO" id="xv3-z2-YA7">
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="none" rowHeight="356" sectionHeaderHeight="22" sectionFooterHeight="22" translatesAutoresizingMaskIntoConstraints="NO" id="xv3-z2-YA7">
<rect key="frame" x="0.0" y="20" width="600" height="580"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes>
Expand All @@ -26,7 +26,7 @@
<autoresizingMask key="autoresizingMask"/>
<subviews>
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" tag="1" contentMode="scaleToFill" alwaysBounceHorizontal="YES" pagingEnabled="YES" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="zwH-6x-S9a">
<rect key="frame" x="0.0" y="0.0" width="600" height="319"/>
<rect key="frame" x="0.0" y="0.0" width="600" height="320"/>
<color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
<collectionViewFlowLayout key="collectionViewLayout" scrollDirection="horizontal" minimumLineSpacing="0.0" minimumInteritemSpacing="0.0" id="4X0-x6-Kkg">
<size key="itemSize" width="320" height="300"/>
Expand Down
1 change: 1 addition & 0 deletions Example/PhotoSliderDemo/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
Expand Down
39 changes: 32 additions & 7 deletions Example/PhotoSliderDemo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import PhotoSlider
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, PhotoSliderDelegate {

@IBOutlet var tableView:UITableView!


var collectionView:UICollectionView!

Expand All @@ -30,6 +31,12 @@ class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSour
return false
}

override func viewDidLayoutSubviews() {
if self.collectionView != nil {
self.collectionView.reloadData()
}
}

// MARK: - UITableViewDataSource

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
Expand All @@ -43,16 +50,21 @@ class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSour
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = self.tableView.dequeueReusableCellWithIdentifier("cell01") as! UITableViewCell

var collectionView = cell.viewWithTag(1) as! UICollectionView
collectionView.delegate = self
collectionView.dataSource = self
self.collectionView = cell.viewWithTag(1) as! UICollectionView
self.collectionView.delegate = self
self.collectionView.dataSource = self

return cell
}

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {

if indexPath.row == 0 {
return UIScreen.mainScreen().bounds.size.width
if UIDevice.currentDevice().orientation == UIDeviceOrientation.Portrait || UIDevice.currentDevice().orientation == UIDeviceOrientation.PortraitUpsideDown {
return tableView.bounds.size.width
} else {
return tableView.bounds.size.height
}
}

return 0.0;
Expand All @@ -78,7 +90,13 @@ class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSour
}

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
return CGSize(width:collectionView.bounds.size.width, height:collectionView.bounds.size.width)

if UIDevice.currentDevice().orientation == UIDeviceOrientation.Portrait || UIDevice.currentDevice().orientation == UIDeviceOrientation.PortraitUpsideDown {
return CGSize(width:collectionView.bounds.size.width, height:collectionView.bounds.size.width)
} else {
return CGSize(width:self.tableView.bounds.size.width, height:collectionView.bounds.size.height)
}

}

// MARK: - UICollectionViewDelegate
Expand All @@ -100,7 +118,14 @@ class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSour
func photoSliderControllerWillDismiss(viewController: PhotoSlider.ViewController) {
UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: UIStatusBarAnimation.Fade)
}


// MARK: - UIContentContainer

internal override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
self.tableView.reloadData()

}

}


9 changes: 9 additions & 0 deletions Pod/Classes/ImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ class ImageView: UIView, UIScrollViewDelegate {
let doubleTabGesture = UITapGestureRecognizer(target: self, action: "didDoubleTap:")
doubleTabGesture.numberOfTapsRequired = 2
self.addGestureRecognizer(doubleTabGesture)

self.imageView.autoresizingMask =
UIViewAutoresizing.FlexibleWidth |
UIViewAutoresizing.FlexibleLeftMargin |
UIViewAutoresizing.FlexibleRightMargin |
UIViewAutoresizing.FlexibleTopMargin |
UIViewAutoresizing.FlexibleHeight |
UIViewAutoresizing.FlexibleBottomMargin

}

func loadImage(imageURL: NSURL) {
Expand Down
Loading

0 comments on commit 00d85a3

Please sign in to comment.