gpt4 book ai didi

iphone - 带有单独纵向和横向图像的 UIBarButtonItem - 从 UINavigationController 弹出 View Controller 时不调用 layoutSubviews

转载 作者:搜寻专家 更新时间:2023-10-30 20:25:25 24 4
gpt4 key购买 nike

我想在 UINavigationController 的 UIToolbar 中显示完全自定义的按钮,并支持纵向和横向。目前我已经实现了一个 RotatingButton(一个 UIView 子类)类,它包含一个 UIButton,它填充了整个 RotatingButton 框架。 RotatingButton 还包含两个图像,用于纵向和横向,并且这些图像的高度不同。然后这个 RotatingButton 作为自定义 View 被包装到 UIBarButtonItem 中。

目前,在 RotatingButton 的 layoutSubviews 中,我正在设置整个 View 的边界,并为按钮设置当前方向的适当图像。这很好用并根据需要处理旋转。

- (void) createLayout {
[self addButtonIfNeeded];
UIDeviceOrientation currentOrientation = [[UIDevice currentDevice] orientation];
if(UIInterfaceOrientationIsLandscape(currentOrientation)) {
[self.button setImage:self.landscapeImage forState:UIControlStateNormal];
self.button.frame = CGRectMake(0.0, 0.0, self.landscapeImage.size.width / 2, self.landscapeImage.size.height / 2);
self.bounds = CGRectMake(0.0, 0.0, self.landscapeImage.size.width / 2, self.landscapeImage.size.height / 2);
} else {
[self.button setImage:self.portraitImage forState:UIControlStateNormal];
self.button.frame = CGRectMake(0.0, 0.0, self.portraitImage.size.width / 2, self.portraitImage.size.height / 2);
self.bounds = CGRectMake(0.0, 0.0, self.portraitImage.size.width / 2, self.portraitImage.size.height / 2);
}
}

- (void) layoutSubviews {
[super layoutSubviews];
[self createLayout];
}

但是,这个问题依然存在:

  1. 以纵向开始查看
  2. 将 View Controller 压入堆栈
  3. 将设备旋转到横向(当前 View react 适当)
  4. 弹出最后一个 View Controller :之前的 View react 良好,但没有调用 RotatingButtons 的 layoutSubviews,并且按钮仍然比应有的大

因此,目前在弹出一个 View Controller 之后,之前的 UIBarButtonItems 没有调用它们的 layoutSubviews,它们仍然太大(或者太小,如果我们从横向开始并在另一个 View 中旋转到纵向)。如何解决这个问题?

最佳答案

这是一个非常棘手的问题。您应该尝试覆盖 viewWillAppear: 以调用 [self.view setNeedsLayout] 以在 View 即将出现时强制更新布局。

关于iphone - 带有单独纵向和横向图像的 UIBarButtonItem - 从 UINavigationController 弹出 View Controller 时不调用 layoutSubviews,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15569478/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com