gpt4 book ai didi

objective-c - iOS 8 表单模式对话框显示后调整大小

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

我在一个应用程序上工作,它通过使用表单模式样式执行 segue 来显示模式弹出窗口,然后是水平翻转动画。在 iOS 7 中,通过调用使表单占据正确的屏幕尺寸:

self.view.superview.bounds = CGRectMake(0,0,300,300);

例如,这会将模态对话框尺寸设置为正确的大小。此模式对话框中还有一个按钮,允许用户查看“更多详细信息”,为此 View 会增长以显示一些其他内容。我们通过为 View 设置动画并调用以将边界设置为父 View 上稍微大一点的内容来再次执行此操作。

例如:

self.view.superview.bounds = CGRectMake(0,0,600,600);

在 iOS 7 中,这非常有效。但在 iOS 8 中它已停止工作。我们现在不必修改父 View 的边界,而是调用:

self.preferredContentSize = CGSizeMake(300, 300);

这解决了打开后的表单外观问题,但之后我找不到一种方法来操纵 View 的大小。设置 super View 边界无效。

我可以在 iOS8 中看到 Apple 对表单进行了更改,使其具有 3 个 View 层次结构(您的 View -> 阴影 View -> 过渡 View -> 窗口),而在 iOS 7 中它只是一个 2 View 层次结构(您的 View -> 阴影 View -> 窗口)。

我试过操纵 super View 的 super View ,但没有达到预期的效果。

还有其他人看到这个/找到解决方法吗?这是一个示例项目:

https://github.com/ingybing/FormSheet

在 iOS 7 模拟器中运行它,您将看到所需的行为。这就是我在 iOS 8 中努力工作的原因

View Controller 示例:

#import "ModalWindowViewController.h"

@interface ModalWindowViewController ()
@property bool minimised;
@property bool isInitialViewLoadLayout;
@end

#define is_iOS8 ([[[UIDevice currentDevice] systemVersion]floatValue] >= 8)

@implementation ModalWindowViewController

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.

self.minimised = YES;
self.isInitialViewLoadLayout = YES;

if(is_iOS8)
{
// Set initial size in iOS 8 etc.
self.preferredContentSize = CGSizeMake(300, 300);
}
}

- (void) viewWillLayoutSubviews
{
if (self.isInitialViewLoadLayout)
{
self.isInitialViewLoadLayout = NO;

if(!is_iOS8)
{
// Set initial size in iOS 6,7 etc.
self.view.superview.bounds = CGRectMake(0, 0, 300, 300);
}
}
}

- (IBAction)minMaxTouched:(id)sender
{
CGRect newSize = CGRectMake(0, 0, 300, 300);

if (self.minimised == YES)
{
newSize = CGRectMake(0, 0, 600, 600);
}

if(is_iOS8)
{
// Doesn't Work
// self.view.superview.bounds = newSize;

// Doesn't seem to do anything either.
self.preferredContentSize = newSize.size;
}
else
{
// Works a treat on ios7
self.view.superview.bounds = newSize;
}

self.minimised = !self.minimised;
}

- (IBAction)closeTouched:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}
@end

最佳答案

经过一番折腾……如果您将 view.superview 的边界更新为某些内容,然后在 superview 上调用 layoutIfNeeded。这将导致调用 willLayoutSubviews 方法。如果您在那里设置 super View 边界,它会更新模态对话框的大小,但如果您在其他任何地方这样做则不会。

示例 View Controller 解决方案:

#import "ModalWindowViewController.h"

@interface ModalWindowViewController ()
@property bool minimised;
@property CGRect windowBounds;
@end

#define is_iOS8 ([[[UIDevice currentDevice] systemVersion]floatValue] >= 8)

@implementation ModalWindowViewController

- (void)viewDidLoad {
[super viewDidLoad];

// Start with a minimised window size.
self.minimised = YES;
self.windowBounds = CGRectMake(0, 0, 300, 300);

if(is_iOS8)
{
// Set initial size in iOS 8 etc.
self.preferredContentSize = self.windowBounds.size;
}
}

- (void) viewWillLayoutSubviews
{
// Resize the window based on it's current required size.
// The supeview bounds only seems to actually changed on screen
// if changed inside this method.
self.view.superview.bounds = self.windowBounds;
}

- (IBAction)minMaxTouched:(id)sender
{
// Toggle the dimensions of the window bases on minimised / maximised state.
if (self.minimised == YES)
{
self.windowBounds = CGRectMake(0, 0, 600, 600);
}
else
{
self.windowBounds = CGRectMake(0, 0, 300, 300);
}

// Set some value that will get overridden in viewWillLayoutSubviews
// You need to change the view bounds or it won't actually invoke a layout.
self.view.superview.bounds = CGRectMake(0, 0, 100, 100);

// Toggle minimised state before we layout.
self.minimised = !self.minimised;

// Manually request a layout. Since the superview bounds have been changed
// to a temporary value it should cause a layout where we set the real
// desired size.
[self.view.superview layoutIfNeeded];
}

- (IBAction)closeTouched:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}
@end

关于objective-c - iOS 8 表单模式对话框显示后调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28490591/

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