Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复手势没设置上的问题:需要通过 setPhoto:(PYPhoto *)photo 设置。 #192

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 41 additions & 3 deletions PYPhotoBrowser/Controller/PYPhotosPreviewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,41 @@ - (void)changeNavBarState
[self setNeedsStatusBarAppearanceUpdate];
self.navigationController.navigationBar.py_y = self.statusBarHidden ? -self.navigationController.navigationBar.py_height : [UIApplication sharedApplication].statusBarFrame.size.height;
} completion:nil];

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在ios11上(可能也在之前的某个版本),[self setNeedsStatusBarAppearanceUpdate]; 动画有点问题,感觉是ios系统的bug (UIView animateWithDuration),改动方案1:直接屏蔽掉。。保留状态栏不动 改动方案2:分开动画,但是在中间的时候有点卡顿。。

/* 改动方案1
[UIView animateWithDuration:duration animations:^{
self.navBarAnimating = YES;
self.statusBarHidden = self.navigationController.navigationBar.py_y > 0;
//[self setNeedsStatusBarAppearanceUpdate];
self.navigationController.navigationBar.py_y = self.statusBarHidden ? -self.navigationController.navigationBar.py_height : [UIApplication sharedApplication].statusBarFrame.size.height;
} completion:nil];
*/

/* 改动方案2
CGFloat statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;
CGFloat navBarHeight = self.navigationController.navigationBar.py_height;
CGFloat proportion = statusBarHeight/(statusBarHeight+navBarHeight);
self.statusBarHidden = self.navigationController.navigationBar.py_y >= 0;
if (!self.statusBarHidden) {
proportion = 1-proportion;
}
[UIView animateWithDuration:duration*proportion animations:^{
self.navBarAnimating = YES;
//self.navigationController.navigationBar.py_y = self.statusBarHidden ? 0 : statusBarHeight-navBarHeight;
self.navigationController.navigationBar.py_y = 0;
if (self.statusBarHidden) {
[self setNeedsStatusBarAppearanceUpdate];
}
} completion:^(BOOL finished) {
[UIView animateWithDuration:duration*(1-proportion) animations:^{
self.navigationController.navigationBar.py_y = self.statusBarHidden ? -(navBarHeight) : statusBarHeight;
if (!self.statusBarHidden) {
[self setNeedsStatusBarAppearanceUpdate];
}
} completion:nil];
}];
*/

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.navBarAnimating = NO;
});
Expand Down Expand Up @@ -194,14 +229,17 @@ - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSe
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

PYPhotoCell *cell = [PYPhotoCell cellWithCollectionView:collectionView indexPath:indexPath];
PYPhoto *photo = [[PYPhoto alloc] init];
id image = self.selectedPhotoView.images[indexPath.item];
if ([image isKindOfClass:[UIImage class]]) {
cell.image = image;
photo.originalImage = image;
} else if ([image isKindOfClass:[PYPhoto class]]) {
cell.photo = (PYPhoto*)image;
photo = (PYPhoto *)image;
} else if ([image isKindOfClass:[NSString class]]) {
[cell.photoView sd_setImageWithURL:[NSURL URLWithString:image] placeholderImage:PYPlaceholderImage];
photo.original_pic = (NSString *)image;
}
// 设置图片
cell.photo = photo;

cell.photoView.isPreview = YES;
return cell;
Expand Down
13 changes: 9 additions & 4 deletions PYPhotoBrowser/View/PYPhotosView.m
Original file line number Diff line number Diff line change
Expand Up @@ -322,15 +322,20 @@ - (void)setImages:(NSMutableArray *)images
photoView.images = images;
if (i < imageCount) {
photoView.hidden = NO;
// 设置图片
PYPhoto *photo = [[PYPhoto alloc] init];
id image = images[i];
if ([image isKindOfClass:[UIImage class]]) {
photoView.image = image;
//photoView.image = image;
photo.originalImage = image;
} else if ([image isKindOfClass:[PYPhoto class]]) {
photoView.photo = (PYPhoto *)image;
//photoView.photo = (PYPhoto *)image;
photo = (PYPhoto *)image;
} else if ([image isKindOfClass:[NSString class]]) {
[photoView sd_setImageWithURL:[NSURL URLWithString:image] placeholderImage:PYPlaceholderImage];
//[photoView sd_setImageWithURL:[NSURL URLWithString:image] placeholderImage:PYPlaceholderImage];
photo.original_pic = (NSString *)image;
}
// 设置图片
photoView.photo = photo;
}else{
photoView.hidden = YES;
}
Expand Down