Skip to content

Commit

Permalink
Merge pull request #3 from BramYeh/supportlandscape
Browse files Browse the repository at this point in the history
Support Landscape
  • Loading branch information
BramYeh authored Jan 14, 2017
2 parents eede53e + c895869 commit 7da9495
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 64 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
# * http://www.objc.io/issue-6/travis-ci.html
# * https://github.com/supermarin/xcpretty#usage

osx_image: xcode7.3
osx_image: xcode8.2
language: objective-c
# cache: cocoapods
# podfile: Example/Podfile
# before_install:
# - gem install cocoapods # Since Travis is not always on latest version
# - pod install --project-directory=Example
script:
- set -o pipefail && xcodebuild test -workspace Example/BAPeekPop.xcworkspace -scheme BAPeekPop-Example -sdk iphonesimulator9.3 ONLY_ACTIVE_ARCH=NO | xcpretty
- set -o pipefail && xcodebuild test -workspace Example/BAPeekPop.xcworkspace -scheme BAPeekPop-Example -sdk iphonesimulator10.2 -destination 'platform=iOS Simulator,name=iPhone 6,OS=9.3' ONLY_ACTIVE_ARCH=NO | xcpretty
- pod lib lint
2 changes: 1 addition & 1 deletion BAPeekPop.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'BAPeekPop'
s.version = '1.0.0'
s.version = '1.1.0'
s.summary = 'Peek & Pop Compat for Long Press on non 3D touch Device of iOS 9+'

# This description is used to generate tags and improve search results.
Expand Down
12 changes: 10 additions & 2 deletions BAPeekPop/Classes/BAConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,20 @@ extern CGFloat const BACornerRadius;

extern CGFloat const BABlurRadius;

extern CGFloat const BAHorizontalMargin;
extern CGFloat const BAHorizontalMarginPortrait;

extern CGFloat const BAVerticalMargin;
extern CGFloat const BAVerticalMarginPortrait;

extern CGFloat const BAHorizontalMarginLandscape;

extern CGFloat const BAVerticalMarginLandscape;

extern CGFloat const BAActionItemHeight;

extern CGFloat const BAActionCollectionViewVerticalMargin;

extern CGFloat const BAPeekOffset;

CGFloat getHorizontalMargin();

CGFloat getVerticalMargin();
24 changes: 22 additions & 2 deletions BAPeekPop/Classes/BAConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,32 @@

CGFloat const BABlurRadius = 5.0f;

CGFloat const BAHorizontalMargin = 10.0f;
CGFloat const BAHorizontalMarginPortrait = 10.0f;

CGFloat const BAVerticalMargin = 30.0f;
CGFloat const BAVerticalMarginPortrait = 30.0f;

CGFloat const BAHorizontalMarginLandscape = 30.0f;

CGFloat const BAVerticalMarginLandscape = 10.0f;

CGFloat const BAActionItemHeight = 44.0f;

CGFloat const BAActionCollectionViewVerticalMargin = 15.0f;

CGFloat const BAPeekOffset = 10.0f;

CGFloat getHorizontalMargin() {
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)) {
// code for landscape orientation
return BAHorizontalMarginLandscape;
}
return BAHorizontalMarginPortrait;
}

CGFloat getVerticalMargin() {
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)) {
// code for landscape orientation
return BAVerticalMarginLandscape;
}
return BAVerticalMarginPortrait;
}
15 changes: 11 additions & 4 deletions BAPeekPop/Classes/BAPreviewingViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ - (void)viewDidLoad {
UICollectionViewFlowLayout *collectionViewLayout = [[UICollectionViewFlowLayout alloc] init];
collectionViewLayout.minimumLineSpacing = 1.0f / [UIScreen mainScreen].scale;
collectionViewLayout.minimumInteritemSpacing = 0.0f;
collectionViewLayout.itemSize = CGSizeMake([UIScreen mainScreen].bounds.size.width - BAHorizontalMargin * 2, BAActionItemHeight);
collectionViewLayout.itemSize = CGSizeMake([UIScreen mainScreen].bounds.size.width - getHorizontalMargin() * 2, BAActionItemHeight);

CGSize preferSize = [self preferFrameOfActionCollectionView].size;
CGRect initActionFrame = CGRectMake(([UIScreen mainScreen].bounds.size.width - preferSize.width) / 2.0f,
Expand Down Expand Up @@ -168,9 +168,16 @@ - (void)didMoveToParentViewController:(UIViewController *)parent {
}
}

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id <UIViewControllerTransitionCoordinator>)coordinator {
// should animate previewing view and then callback function
if ([self.delegate respondsToSelector:@selector(previewingViewControllerDidDismiss:)]) {
[self.delegate previewingViewControllerDidDismiss:self];
}
}

- (CGRect)defaultFrameOfPreviewingController {
// TODO, need to survey iOS's default 3D touch previewing rect
CGRect defaultFrame = CGRectInset([UIScreen mainScreen].bounds, BAHorizontalMargin, BAVerticalMargin);
CGRect defaultFrame = CGRectInset([UIScreen mainScreen].bounds, getHorizontalMargin(), getVerticalMargin());
CGSize preferredContentSize = self.peekViewController.preferredContentSize;

// invalid preferredContentSize, return default frame
Expand All @@ -185,7 +192,7 @@ - (CGRect)defaultFrameOfPreviewingController {
}
if (defaultFrame.size.height < preferredContentSize.height) {
preferredContentSize.height = defaultFrame.size.height;
preferredContentSize.width = defaultFrame.size.width / ratio;
preferredContentSize.width = defaultFrame.size.height / ratio;
}

return CGRectMake(([UIScreen mainScreen].bounds.size.width - preferredContentSize.width) / 2.0f,
Expand All @@ -201,7 +208,7 @@ - (CGRect)preferFrameOfActionCollectionView {
height = [UIScreen mainScreen].bounds.size.height * 0.65f; // default height
}

CGSize preferSize = CGSizeMake([UIScreen mainScreen].bounds.size.width - BAHorizontalMargin * 2, height);
CGSize preferSize = CGSizeMake([UIScreen mainScreen].bounds.size.width - getHorizontalMargin() * 2, height);

return CGRectMake(([UIScreen mainScreen].bounds.size.width - preferSize.width) / 2.0f,
[UIScreen mainScreen].bounds.size.height - preferSize.height - BAActionCollectionViewVerticalMargin,
Expand Down
12 changes: 11 additions & 1 deletion Example/BAPeekPop/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,20 @@ - (BOOL)prefersStatusBarHidden {
return YES;
}

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
[self.collectionView.collectionViewLayout invalidateLayout];
}

#pragma mark - UICollectionViewDelegateFlowLayout

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
CGFloat size = self.view.bounds.size.width / 2.0f - 15.0f;
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)) {
// code for landscape orientation
size = self.view.bounds.size.width / 3.0f - 15.0f;;
}
return CGSizeMake(size, size);
}

Expand Down
Loading

0 comments on commit 7da9495

Please sign in to comment.