菜鸟教程小白 发表于 2022-12-11 16:48:04

ios - UIPageViewController 中的导航栏错误


                                            <p><p>我有 <em>vertical</em> UIPageViewController 和 <em>scroll</em> 过渡模式。
<br/>底 ViewController 有导航 Controller ,不显示顶栏。
顶 ViewController 有另一个导航 Controller ,但显示顶栏。
<br/><br/>当我滚动到顶部时,VC 导航栏发生了变化。
在滚动动画帧结束之前正确。但他突然换帧后。我不知道这个东西是怎么解决的。</p>

<p> <a href="/image/KXNyu.png" rel="noreferrer noopener nofollow"><img src="/image/KXNyu.png" alt="Before animation ending"/></a>
<a href="/image/g7tHj.png" rel="noreferrer noopener nofollow"><img src="/image/g7tHj.png" alt="After animation ending"/></a> </p>

<p>有什么想法吗?</p>

<p><strong>PageViewController:</strong></p>

<pre><code>@interface FRTVerticalPageViewController () &lt;UIPageViewControllerDataSource, UIPageViewControllerDelegate, UIScrollViewDelegate&gt;
@property(strong, nonatomic) NSArray *controllers;

@end

@implementation FRTVerticalPageViewController

- (void)viewDidLoad {
;

self.dataSource = self;
self.delegate = self;
self.controllers = ;
for (UIScrollView *view in self.view.subviews) {
    if (]) {
      view.delegate = self;
      view.directionalLockEnabled = YES;
    }
}

]
               direction:UIPageViewControllerNavigationDirectionForward
                  animated:NO
                completion:nil];
}


#pragma mark - Public

- (void)showViewControllerForIndex:(NSInteger)index {
UIViewController *currentVC = self.viewControllers.firstObject;
if (currentVC != self.controllers) {
    ]
                   direction:NO
                  animated:NO
                  completion:nil];
}
}

#pragma mark - Private

- (NSArray&lt;UIViewController *&gt; *)controllersToShowing {
UIViewController *mainPager = ;

UIStoryboard *storyboard = ;
UIViewController *profilePager = ;

NSArray *viewController = @;
return viewController;
}

#pragma mark - UIPageViewControllerDataSource

- (nullable UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
NSInteger indexOfController = ;
if (indexOfController == 0) {
    return nil;
}

return self.controllers;
}


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

return self.controllers;
}

#pragma mark - UIPageViewControllerDelegate

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

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

<p>UIPageViewController 顶部的 UINavigation Controller 中的 Root ViewController :</p>

<pre><code>@interface FRTProfileViewController () &lt;UIImagePickerControllerDelegate,
                                        UINavigationControllerDelegate,
                                        UIActionSheetDelegate,
                                        TOCropViewControllerDelegate,
                                        LGAlertViewDelegate,
                                        UIAlertViewDelegate&gt;

@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 {
;

self.avatarSettingsButton.hidden = YES;
self.avatarSettingsButton.layer.masksToBounds = YES;
self.avatarSettingsButton.layer.borderColor = .CGColor;
self.avatarSettingsButton.layer.borderWidth = 2.f;
__weak FRTProfileViewController *weakSelf = self;
FRTUser *user = .user;

self.userAvatarImageView.layer.cornerRadius =
      CGRectGetWidth(weakSelf.userAvatarImageView.bounds) / 2;
self.userAvatarImageView.layer.masksToBounds = YES;
self.userAvatarImageView.layer.borderColor = .CGColor;
self.userAvatarImageView.layer.borderWidth = 2.f;
[self.userAvatarImageView sd_setImageWithURL:user.avatarImageURL
      placeholderImage:
      completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
          weakSelf.avatarSettingsButton.hidden = NO;
      }];

self.inboxCountLabel.text =
      self.friendsCountLabel.text =
      self.sentCountLabel.text = @&#34;0&#34;;

}

- (void)viewDidLayoutSubviews {
;

;
self.userAvatarImageView.layer.cornerRadius =
    self.avatarSettingsButton.layer.cornerRadius =
      CGRectGetWidth(self.userAvatarImageView.bounds) / 2;
}

- (void)viewWillAppear:(BOOL)animated {
;

;

__weak FRTProfileViewController *weakSelf = self;
[ loadUserDetailsWithId:nil
      success:^(id responsedObject) {
          FRTUser *user =
                                    fromJSONDictionary:responsedObject
                                                 error:nil];
          .user = user;
          ;
      } failure:^(NSError *error) {
          NSLog(@&#34;User info loading failed. Reason:\n%@&#34;, error.localizedDescription);
      }];
}
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您可以检查每个 ViewController 的此参数。也许,当你在它们之间切换时,会发生一些变化:</p>

<pre><code>viewController.navigationController.navigationBar.translucent = NO;
[ setStatusBarHidden:NO]
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - UIPageViewController 中的导航栏错误,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/37967268/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/37967268/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - UIPageViewController 中的导航栏错误