Skip to content

Commit

Permalink
Adaptation iPad and fixed #56 display of view on iPad
Browse files Browse the repository at this point in the history
Adaptation iPad and fixed #56 display of view on iPad
  • Loading branch information
ko1o committed Feb 14, 2017
1 parent f94dbda commit eea3ce2
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 120 deletions.
20 changes: 16 additions & 4 deletions PYPhotoBrowser/Controller/PYPhotosReaderController.m
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,20 @@ - (void)hiddenPhoto
}];
}

/** 该控制器不受项目的Device Orientation配置影响 */
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(BOOL)shouldAutorotate
{
return NO;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}

// 监听屏幕旋转
- (void)deviceOrientationDidChange
{
Expand Down Expand Up @@ -336,8 +350,8 @@ - (void)deviceOrientationDidChange
}

// 判断即将显示哪一张
// 执行旋转动画
__block UIWindow *tempWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
// 执行旋转动画(保证黑色背景足够大)
__block UIWindow *tempWindow = [[UIWindow alloc] initWithFrame:CGRectMake(-6000, -6000, 12000, 12000)];
tempWindow.windowLevel = UIWindowLevelStatusBar;
// 自动调节宽高
self.collectionView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
Expand Down Expand Up @@ -388,8 +402,6 @@ - (void)deviceOrientationDidChange
}];
}



#pragma mark - UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
Expand Down
36 changes: 23 additions & 13 deletions PYPhotoBrowser/View/PYPhotoView.m
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,30 @@ - (void)imageDidLongPress:(UITapGestureRecognizer *)longPress
// 如果实现了代理方法,直接返回,不使用默认的操作
if([browseView.delegate respondsToSelector:@selector(photoBrowseView:didLongPressImage:index:)]) return;
}
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *savePhotoAction = [UIAlertAction actionWithTitle:@"保存到相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
// 保存到相册
UIImageWriteToSavedPhotosAlbum(self.image, self, @selector(image: didFinishSavingWithError: contextInfo:), nil);
}];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:savePhotoAction];
[alertController addAction:cancelAction];

// 跳出提示
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"保存到相册", nil];
sheet.delegate = self;
[sheet showInView:self.window];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{ // iPad
UIPopoverPresentationController *popover = alertController.popoverPresentationController;
if (popover){
popover.sourceView = self.window;
popover.sourceRect = CGRectMake((PYRealyScreenW - 100) * 0.5, PYRealyScreenH, 100, 100);
popover.permittedArrowDirections = UIPopoverArrowDirectionDown;
}
// 跳出提示
[self.window.rootViewController presentViewController:alertController animated:YES completion:nil];
} else { // iPhone

// 跳出提示
[self.window.rootViewController presentViewController:alertController animated:YES completion:nil];
}
}
}

Expand Down Expand Up @@ -674,15 +693,6 @@ - (CGPoint)setAnchorPointBaseOnGestureRecognizer:(UIGestureRecognizer *)gr


#pragma mark - PYAcitonSheetDeleagate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0) {
NSLog(@"保存到相册");
UIImageWriteToSavedPhotosAlbum(self.image, self, @selector(image: didFinishSavingWithError: contextInfo:), nil);
} else if (buttonIndex == 2) {
NSLog(@"取消");
}
}

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
Expand Down
Loading

0 comments on commit eea3ce2

Please sign in to comment.