• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - UIPageViewController 中的导航栏错误

[复制链接]
菜鸟教程小白 发表于 2022-12-11 16:48:04 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我有 vertical UIPageViewController 和 scroll 过渡模式。
底 View Controller 有导航 Controller ,不显示顶栏。 顶 View Controller 有另一个导航 Controller ,但显示顶栏。

当我滚动到顶部时,VC 导航栏发生了变化。 在滚动动画帧结束之前正确。但他突然换帧后。我不知道这个东西是怎么解决的。

Before animation ending After animation ending

有什么想法吗?

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);
      }];
}



Best Answer-推荐答案


您可以检查每个 View Controller 的此参数。也许,当你在它们之间切换时,会发生一些变化:

viewController.navigationController.navigationBar.translucent = NO;
[[UIApplication sharedApplication] setStatusBarHidden:NO]

关于ios - UIPageViewController 中的导航栏错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37967268/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap