2

私は、の垂直 UIPageViewControllerをスクロール遷移モードとしています。
ボトムビューコントローラには、トップバーを表示しないナビゲーションコントローラがあります。 トップビューコントローラには別のナビゲーションコントローラがありますが、トップバーが表示されています。

トップにスクロールすると、VCナビゲーションバーが変更されます。 スクロールアニメーションフレームが終了する前に正しい。しかし、彼は突然フレームを変更した後。私はこのことをどうやって解決したのか分かりません。UIPageViewControllerのナビゲーションバーのバグ

Before animation ending After animation ending

任意のアイデア?

PageViewController:UIPageViewControllerのトップでUINavigationコントローラーで

@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)showViewControllerForIndex:(NSInteger)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:@"ProfilePageController"]; 

    NSArray *viewController = @[profilePager, mainPager]; 
    return viewController; 
} 

#pragma mark - UIPageViewControllerDataSource 

- (nullable UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController { 
    NSInteger indexOfController = [self.controllers indexOfObject:viewController]; 
    if (indexOfController == 0) { 
    return nil; 
    } 

    return self.controllers[indexOfController - 1]; 
} 


- (nullable UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController { 
    NSInteger indexOfController = [self.controllers indexOfObject:viewController]; 
    if (indexOfController == self.controllers.count - 1) { 
    return nil; 
    } 

    return self.controllers[indexOfController + 1]; 
} 

#pragma mark - UIPageViewControllerDelegate 

- (void)pageViewController:(UIPageViewController *)pageViewController willTransitionToViewControllers:(NSArray<UIViewController *> *)pendingViewControllers { 
    self.inScrolling = YES; 
    UIPageViewController *pageVC = self.viewControllers.firstObject; 
    UINavigationController *navVC = pageVC.viewControllers.firstObject; 
    NSLog(@"1:%@", NSStringFromCGRect(navVC.navigationBar.bounds)); 
} 

- (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray<UIViewController *> *)previousViewControllers transitionCompleted:(BOOL)completed { 
    self.inScrolling = NO; 
    UIPageViewController *pageVC = self.viewControllers.firstObject; 
    UINavigationController *navVC = pageVC.viewControllers.firstObject; 
    NSLog(@"2:%@", NSStringFromCGRect(navVC.navigationBar.bounds)); 
} 

ルートビューコントローラ:

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

をあなたのコードを共有し、あなたのコードに何か問題があるに違いありません。 – Kampai

+0

UIPageViewControllerには2ページ-2のナビゲーションコントローラがあります。 –

答えて

0

あなたはそれぞれのViewControllerのために、このパラメータをチェックすることができます。あなたが変更を取得、それらの間に何かを切り替えると多分、:

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

私はそれを以前に使っています。それは動作しません。ステータスバーが表示されているので、ステータスバーではないと思います。ナビゲーションバーの高さが変わります。 –

関連する問題