2

我正在尝试打印应用程序可见和隐藏窗口的视图层次结构。这是我在 MFMessageComposeViewController 子类中的一部分代码:

NSArray *windows = [[UIApplication sharedApplication] windows];

for(UIWindow *aWindow in windows) {
    if([aWindow isMemberOfClass:NSClassFromString(@"UITextEffectsWindow")]) {
        sendButton = [self findButtonInView:aWindow];
            break;
    }
}

findButtonInView: 方法在当前 UIWindow 中递归搜索 UIButton。

这在使用 iOS4.3 和 iOS 5.1 进行测试时按预期工作(成功找到预期的 UIButton),但不适用于 iOS6。以下是两个测试的视图层次打印结果:

iOS 4.3:

<UITextEffectsWindow: 0x1e32a0; frame = (0 0; 320 480); opaque = NO; layer = <CALayer: 0x1e33d0>>
   | <UIPeripheralHostView: 0x1e4a80; frame = (0 224; 320 256); autoresizesSubviews = NO; layer = <UIPeripheralHostLayer: 0x1e4e60>>
   |    | <UIKeyboardAutomatic: 0x1ad300; frame = (0 40; 320 216); opaque = NO; layer = <CALayer: 0x1ad3b0>>
   |    |    | <UIKeyboardImpl: 0x1ad520; frame = (0 0; 320 216); opaque = NO; layer = <CALayer: 0x1ad6c0>>
   |    |    |    | <UIKeyboardLayoutStar: 0x1d47c0; frame = (0 0; 320 216); layer = <CALayer: 0x19ca40>>
   |    |    |    |    | <UIKBKeyplaneView: 0x1df880; frame = (0 0; 320 216); layer = <CALayer: 0x1df900>>
   |    |    |    |    |    | <UIKBKeyView: 0x1dfe00; frame = (1 119; 40 42); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1dffd0>>
   |    |    |    |    |    | <UIKBKeyView: 0x1e0090; frame = (279 119; 40 42); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1e00e0>>
   |    |    |    |    |    | <UIKBKeyView: 0x1e01e0; frame = (1 173; 38 42); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1e0230>>
   |    |    |    |    |    | <UIKBKeyView: 0x1dbfb0; frame = (41 173; 38 42); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1dc050>>
   |    |    |    |    |    | <UIKBKeyView: 0x1e0330; frame = (81 173; 158 42); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1e0380>>
   |    |    |    |    |    | <UIKBKeyView: 0x1e0440; frame = (241 173; 78 42); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1e0490>>
   |    | <CKMessageEntryView: 0x182500; baseClass = UIImageView; frame = (0 0; 320 40); opaque = NO; autoresize = W+TM; layer = <CALayer: 0x1837c0>>
   |    |    | <UIButton: 0x1878c0; frame = (6 8; 26 27); hidden = YES; opaque = NO; autoresize = RM+TM; layer = <CALayer: 0x182e60>>
   |    |    |    | <UIImageView: 0x1e56f0; frame = (0 0; 26 27); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1e5720>>
   |    |    | <UIView: 0x184dd0; frame = (7 0; 245 40); autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0x185130>>
   |    |    | <CKContentEntryView: 0x188a50; baseClass = UIScrollView; frame = (6 0; 249 40); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x187230>; contentOffset: {-0, -10}>
   |    |    |    | <CKRichContentView: 0x193790; baseClass = UITextContentView; frame = (0 0; 249 20); text = ''; autoresize = W; layer = <CALayer: 0x1938a0>>
   |    |    |    |    | <UIWebDocumentView: 0xaef200; frame = (0 0; 249 20); text = '
'; opaque = NO; userInteractionEnabled = NO; layer = <UIWebLayer: 0x196c20>>
   |    |    |    |    | <UITextSelectionView: 0x1a5b60; frame = (0 0; 0 0); userInteractionEnabled = NO; layer = <CALayer: 0x1a5c00>>
   |    |    |    | <UIImageView: 0x189fa0; frame = (242 10; 7 20); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = <CALayer: 0x189ff0>>
   |    |    |    | <UIImageView: 0x189eb0; frame = (242 23; 7 7); alpha = 0; opaque = NO; autoresize = TM; userInteractionEnabled = NO; layer = <CALayer: 0x189f00>>
   |    |    | <UIImageView: 0x18a190; frame = (7 0; 245 40); opaque = NO; autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0x18a510>>
   |    |    | <UILabel: 0x18a6b0; frame = (245 13; 73 15); text = 'TEST'; clipsToBounds = YES; hidden = YES; opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = <CALayer: 0x18a720>>
   |    |    | <UIButton: 0x180d00; frame = (252 8; 61 27); opaque = NO; autoresize = LM+TM; layer = <CALayer: 0x184e00>>
   |    |    |    | <UIImageView: 0x1ad460; frame = (0 0; 61 27); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1ad490>>
   |    |    |    | <UIButtonLabel: 0x1871c0; frame = (11 3; 39 20); text = 'Send'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x187280>>

iOS 6.0:

<UIWindow: 0x1fd81f80; frame = (0 0; 320 480); opaque = NO; autoresize = RM+BM; layer = <UIWindowLayer: 0x1fd82080>>
   | <UILayoutContainerView: 0x1fd94d50; frame = (0 0; 320 480); autoresize = W+H; layer = <CALayer: 0x1fd94df0>>
   |    | <UINavigationTransitionView: 0x1fd9a450; frame = (0 0; 320 480); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x1fd9a520>>
   |    |    | <UIViewControllerWrapperView: 0x1fdac9a0; frame = (0 20; 320 460); autoresize = W+H; layer = <CALayer: 0x1fdaca30>>
   |    |    |    | <UIView: 0x1fda8cb0; frame = (0 0; 320 460); autoresize = W+H; layer = <CALayer: 0x1fda8c70>>
   |    |    |    |    | <_UISizeTrackingView: 0x1fda6430; frame = (0 0; 320 460); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x1fda6510>>
   |    |    |    |    |    | <_UIRemoteView: 0x1fda6700; frame = (0 0; 320 480); transform = [0.5, -0, 0, 0.5, -0, 0]; userInteractionEnabled = NO; layer = <CALayerHost: 0x1fda6850>>

我的问题是如何在 UITextEffectsWindow 中找到所需的 UIButton?

似乎iOS6中的视图层次结构发生了某种变化......

我将不胜感激任何帮助。谢谢!

4

1 回答 1

1

很可能是它改变了。您正在访问 UI 中显示的未记录元素,这些元素不能保证在系统更新之间保持一致。如果您想更改 MFMailComposeViewController 类中呈现的 UI 元素的外观,请使用 IUAppearance API。您不应该访问大部分邮件控制器类。

重要邮件撰写界面本身是不可定制的,并且不能由您的应用程序修改。此外,在呈现界面后,您的应用程序不允许对电子邮件内容进行进一步的更改。用户仍然可以使用界面编辑内容,但程序更改会被忽略。因此,您必须在呈现界面之前设置内容字段的值。

于 2012-10-22T15:59:53.170 回答