我有 vertical UIPageViewController 和 scroll 过渡模式。
底 View Controller 有导航 Controller ,不显示顶栏。
顶 View Controller 有另一个导航 Controller ,但显示顶栏。
当我滚动到顶部时,VC 导航栏发生了变化。
在滚动动画帧结束之前正确。但他突然换帧后。我不知道这个东西是怎么解决的。
有什么想法吗?
PageViewController:
@interface FRTVerticalPageViewController () <UIPageViewControllerDataSource, UIPageViewControllerDelegate, UIScrollViewDelegate>
@property(strong, nonatomic) NSArray *controllers;
@end
@implementation FRTVerticalPageViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.dataSource = self;
self.delegate = self;
self.controllers = [self controllersToShowing];
for (UIScrollView *view in self.view.subviews) {
if ([view isKindOfClass:[UIScrollView class]]) {
view.delegate = self;
view.directionalLockEnabled = YES;
}
}
[self setViewControllers[self.controllers[1]]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:nil];
}
#pragma mark - Public
- (void)showViewControllerForIndexNSInteger)index {
UIViewController *currentVC = self.viewControllers.firstObject;
if (currentVC != self.controllers[index]) {
[self setViewControllers[self.controllers[index]]
direction:NO
animated:NO
completion:nil];
}
}
#pragma mark - Private
- (NSArray<UIViewController *> *)controllersToShowing {
UIViewController *mainPager = [self.storyboard instantiateViewControllerWithIdentifier"MainPageController"];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:kFRTProfileStoryboardName bundle:nil];
UIViewController *profilePager = [storyboard instantiateViewControllerWithIdentifier"rofilePageController"];
NSArray *viewController = @[profilePager, mainPager];
return viewController;
}
#pragma mark - UIPageViewControllerDataSource
- (nullable UIViewController *)pageViewControllerUIPageViewController *)pageViewController viewControllerBeforeViewControllerUIViewController *)viewController {
NSInteger indexOfController = [self.controllers indexOfObject:viewController];
if (indexOfController == 0) {
return nil;
}
return self.controllers[indexOfController - 1];
}
- (nullable UIViewController *)pageViewControllerUIPageViewController *)pageViewController viewControllerAfterViewControllerUIViewController *)viewController {
NSInteger indexOfController = [self.controllers indexOfObject:viewController];
if (indexOfController == self.controllers.count - 1) {
return nil;
}
return self.controllers[indexOfController + 1];
}
#pragma mark - UIPageViewControllerDelegate
- (void)pageViewControllerUIPageViewController *)pageViewController willTransitionToViewControllersNSArray<UIViewController *> *)pendingViewControllers {
self.inScrolling = YES;
UIPageViewController *pageVC = self.viewControllers.firstObject;
UINavigationController *navVC = pageVC.viewControllers.firstObject;
NSLog(@"1:%@", NSStringFromCGRect(navVC.navigationBar.bounds));
}
- (void)pageViewControllerUIPageViewController *)pageViewController didFinishAnimatingBOOL)finished previousViewControllersNSArray<UIViewController *> *)previousViewControllers transitionCompleted:(BOOL)completed {
self.inScrolling = NO;
UIPageViewController *pageVC = self.viewControllers.firstObject;
UINavigationController *navVC = pageVC.viewControllers.firstObject;
NSLog(@"2:%@", NSStringFromCGRect(navVC.navigationBar.bounds));
}
UIPageViewController 顶部的 UINavigation Controller 中的 Root View Controller :
@interface FRTProfileViewController () <UIImagePickerControllerDelegate,
UINavigationControllerDelegate,
UIActionSheetDelegate,
TOCropViewControllerDelegate,
LGAlertViewDelegate,
UIAlertViewDelegate>
@property (weak, nonatomic) IBOutlet UIImageView *userAvatarImageView;
@property (weak, nonatomic) IBOutlet UILabel *descriptionLabel;
@property (weak, nonatomic) IBOutlet UIButton *avatarSettingsButton;
@property (weak, nonatomic) IBOutlet UILabel *inboxCountLabel;
@property (weak, nonatomic) IBOutlet UILabel *friendsCountLabel;
@property (weak, nonatomic) IBOutlet UILabel *sentCountLabel;
@end
@implementation FRTProfileViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.avatarSettingsButton.hidden = YES;
self.avatarSettingsButton.layer.masksToBounds = YES;
self.avatarSettingsButton.layer.borderColor = [UIColor whiteColor].CGColor;
self.avatarSettingsButton.layer.borderWidth = 2.f;
__weak FRTProfileViewController *weakSelf = self;
FRTUser *user = [FRTUserManager sharedManager].user;
self.userAvatarImageView.layer.cornerRadius =
CGRectGetWidth(weakSelf.userAvatarImageView.bounds) / 2;
self.userAvatarImageView.layer.masksToBounds = YES;
self.userAvatarImageView.layer.borderColor = [UIColor whiteColor].CGColor;
self.userAvatarImageView.layer.borderWidth = 2.f;
[self.userAvatarImageView sd_setImageWithURL:user.avatarImageURL
placeholderImage:[UIImage imageNamed"im_avatar_placeholder"]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
weakSelf.avatarSettingsButton.hidden = NO;
}];
self.inboxCountLabel.text =
self.friendsCountLabel.text =
self.sentCountLabel.text = @"0";
}
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
[self.view layoutIfNeeded];
self.userAvatarImageView.layer.cornerRadius =
self.avatarSettingsButton.layer.cornerRadius =
CGRectGetWidth(self.userAvatarImageView.bounds) / 2;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self updateUserInfoInController];
__weak FRTProfileViewController *weakSelf = self;
[[FRTNetworkManager sharedManager] loadUserDetailsWithId:nil
success:^(id responsedObject) {
FRTUser *user = [MTLJSONAdapter modelOfClass:[FRTUser class]
fromJSONDictionary:responsedObject
error:nil];
[FRTUserManager sharedManager].user = user;
[weakSelf updateUserInfoInController];
} failure:^(NSError *error) {
NSLog(@"User info loading failed. Reason:\n%@", error.localizedDescription);
}];
}
您可以检查每个 View Controller 的此参数。也许,当你在它们之间切换时,会发生一些变化:
viewController.navigationController.navigationBar.translucent = NO;
[[UIApplication sharedApplication] setStatusBarHidden:NO]
关于ios - UIPageViewController 中的导航栏错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37967268/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (https://ogeek.cn/) | Powered by Discuz! X3.4 |