UIWindow 在 addSubview 之后不更新子视图
Posted
技术标签:
【中文标题】UIWindow 在 addSubview 之后不更新子视图【英文标题】:UIWindow doesn't updating subviews after addSubview 【发布时间】:2014-02-10 09:27:32 【问题描述】:我正在将一个 UIView 作为子视图添加到当前的 keyWindow,它显示得很好。 然后,当我更新子视图(UILabel、UIButton、UIImageView 等)时,它不会得到更新。 我尝试在任何地方添加 setNeedDisplay 以便它可以更新它,但仍然没有运气。
添加到 UIWindow:
trapAlarmActivity = [[TrapAlarm alloc] initWithUserInfo:params];
[trapAlarmActivity setNeedsDisplay];
[trapAlarmActivity.screenView setNeedsDisplay];
[[UIApplication sharedApplication].keyWindow addSubview:trapAlarmActivity];
[[UIApplication sharedApplication].keyWindow setNeedsDisplay];
更新 UIWindow:
- (void)changeMessageBoxWithDistance:(NSInteger)distanceToTrap
distanceToTrap += arc4random()%100;
distance = distanceToTrap;
dispatch_async(dispatch_get_main_queue(), ^
NSLog(@"************changeMessageBoxWithDistance: %i", distanceToTrap);
trapType = globalTrap.getTrapType;
if ([ref integerForKey:kUpdate_Distance] == kACTIVE && trapType != CAMERA_LASER)
self.labelDistance.text = [NSString stringWithFormat:@"%i %@", distance, NSLocalizedString(@"meters", nil)];
self.labelDescription.text = globalTrap.getTrapDesc;
self.labelTrapType.text = GetTrapTypeString(trapType);
else
self.labelDistance.text = globalTrap.getTrapDesc;
self.labelDescription.text = GetTrapTypeString(trapType);
self.labelTrapType.text = @"";
[self setNeedsDisplay];
[[UIApplication sharedApplication].keyWindow setNeedsDisplay];
[[UIApplication sharedApplication].windows.firstObject setNeedsDisplay];
/*NSEnumerator *frontToBackWindows = [UIApplication sharedApplication].windows.reverseObjectEnumerator;
for (UIWindow *window in frontToBackWindows)
[window setNeedsDisplay];
*/
);
UPDATE-1:
更新代码以在主线程上工作,仍然没有运气。 只有第一个 UIView 添加为显示的子视图。
UPDATE-2:
当 UIView 出现在 keyWindow 之上时的recursiveDescription:
(lldb) po [[[UIApplication sharedApplication] keyWindow] recursiveDescription]
<UIWindow: 0xd064f20; frame = (0 0; 320 568); autoresize = W+H; gestureRecognizers = <NSArray: 0xd05ecd0>; layer = <UIWindowLayer: 0xd05db90>>
| <SWRevealView: 0xd126130; frame = (0 0; 320 568); autoresize = W+H; layer = <CALayer: 0xd126250>>
| | <UIView: 0xd126400; frame = (0 0; 320 568); autoresize = W+H; gestureRecognizers = <NSArray: 0xd0a2b00>; layer = <CALayer: 0xd126480>>
| | | <UILayoutContainerView: 0xd0909a0; frame = (0 0; 320 568); autoresize = W+H; gestureRecognizers = <NSArray: 0xd093830>; layer = <CALayer: 0xd0894b0>>
| | | | <UINavigationTransitionView: 0xd091310; frame = (0 0; 320 568); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0xd091aa0>>
| | | | | <UIViewControllerWrapperView: 0xd578160; frame = (0 0; 320 568); autoresize = RM+BM; layer = <CALayer: 0xd578230>>
| | | | | | <UIView: 0xd12b620; frame = (0 0; 320 568); autoresize = RM+BM; layer = <CALayer: 0xd12b420>>
| | | | | | | <UIImageView: 0xd12a370; frame = (0 64; 320 67); autoresize = BM; userInteractionEnabled = NO; layer = <CALayer: 0xd12a300>>
| | | | | | | <UITableView: 0xe1d1600; frame = (0 191; 320 377); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0xd081790>; layer = <CALayer: 0xd025310>; contentOffset: 0, 0>
| | | | | | | | <UITableViewWrapperView: 0xd097cc0; frame = (0 0; 320 377); autoresize = W+H; layer = <CALayer: 0xd097dd0>>
| | | | | | | | | <UITableViewCell: 0x12a48000; frame = (0 315; 320 63); text = ' '; autoresize = W; tag = 5; layer = <CALayer: 0x12a48190>>
| | | | | | | | | | <UITableViewCellScrollView: 0x12a48a70; frame = (0 0; 320 63); autoresize = W+H; gestureRecognizers = <NSArray: 0x12a48d00>; layer = <CALayer: 0x12a48c40>; contentOffset: 0, 0>
| | | | | | | | | | | <_UITableViewCellSeparatorView: 0x12a48950; frame = (15 62; 305 1); layer = <CALayer: 0x12a489c0>>
| | | | | | | | | | | <UITableViewCellContentView: 0x12a481c0; frame = (0 0; 320 62.5); opaque = NO; gestureRecognizers = <NSArray: 0x12a492f0>; layer = <CALayer: 0x12a48230>>
| | | | | | | | | | | | <UIImageView: 0x12a48260; frame = (9 8; 45 45); clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; tag = 32; layer = <CALayer: 0x12a482e0>>
| | | | | | | | | | | | <UILabel: 0x12a48310; frame = (73 -15; 227 21); text = ''; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; tag = 30; layer = <CALayer: 0x12a483c0>>
| | | | | | | | | | | | <UILabel: 0x12a486e0; frame = (73 37; 227 21); text = 'היום כולם ידעו על האפליקצ...'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; tag = 31; layer = <CALayer: 0x12a48790>>
| | | | | | | | | | | | <UILabel: 0x12a49ae0; frame = (15 0; 290 62.5); text = ' '; userInteractionEnabled = NO; layer = <CALayer: 0x12a49b90>>
| | | | | | | | | | | <_UITableViewCellSeparatorView: 0x12a490a0; frame = (15 62.5; 305 0.5); layer = <CALayer: 0x12a48610>>
| | | | | | | | | <UITableViewCell: 0x12a44230; frame = (0 252; 320 63); text = ' '; autoresize = W; tag = 4; layer = <CALayer: 0x12a443c0>>
| | | | | | | | | | <UITableViewCellScrollView: 0x12a44ca0; frame = (0 0; 320 63); autoresize = W+H; gestureRecognizers = <NSArray: 0x12a44f30>; layer = <CALayer: 0x12a44e70>; contentOffset: 0, 0>
| | | | | | | | | | | <_UITableViewCellSeparatorView: 0x12a44b80; frame = (15 62; 305 1); layer = <CALayer: 0x12a44bf0>>
| | | | | | | | | | | <UITableViewCellContentView: 0x12a443f0; frame = (0 0; 320 62.5); opaque = NO; gestureRecognizers = <NSArray: 0x12a45520>; layer = <CALayer: 0x12a44460>>
| | | | | | | | | | | | <UIImageView: 0x12a44490; frame = (9 8; 45 45); clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; tag = 32; layer = <CALayer: 0x12a44510>>
| | | | | | | | | | | | <UILabel: 0x12a44540; frame = (73 -15; 227 21); text = ''; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; tag = 30; layer = <CALayer: 0x12a445f0>>
| | | | | | | | | | | | <UILabel: 0x12a44910; frame = (73 37; 227 21); text = ' גלאי מכמונות סלולארי אתכ...'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; tag = 31; layer = <CALayer: 0x12a449c0>>
| | | | | | | | | | | | <UILabel: 0x12a45d10; frame = (15 0; 290 62.5); text = ' '; userInteractionEnabled = NO; layer = <CALayer: 0x12a45dc0>>
| | | | | | | | | | | <_UITableViewCellSeparatorView: 0x12a452d0; frame = (15 62.5; 305 0.5); layer = <CALayer: 0x12a44840>>
| | | | | | | | | <UITableViewCell: 0x12a40790; frame = (0 189; 320 63); text = ' '; autoresize = W; tag = 3; layer = <CALayer: 0x12a40920>>
| | | | | | | | | | <UITableViewCellScrollView: 0x12a411b0; frame = (0 0; 320 63); autoresize = W+H; gestureRecognizers = <NSArray: 0x12a41440>; layer = <CALayer: 0x12a41380>; contentOffset: 0, 0>
| | | | | | | | | | | <_UITableViewCellSeparatorView: 0x12a410e0; frame = (15 62; 305 1); layer = <CALayer: 0xd0b0590>>
| | | | | | | | | | | <UITableViewCellContentView: 0x12a40950; frame = (0 0; 320 62.5); opaque = NO; gestureRecognizers = <NSArray: 0x12a41840>; layer = <CALayer: 0x12a409c0>>
| | | | | | | | | | | | <UIImageView: 0x12a409f0; frame = (9 8; 45 45); clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; tag = 32; layer = <CALayer: 0x12a40a70>>
| | | | | | | | | | | | <UILabel: 0x12a40aa0; frame = (73 -15; 227 21); text = ''; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; tag = 30; layer = <CALayer: 0x12a40b50>>
| | | | | | | | | | | | <UILabel: 0x12a40e70; frame = (73 37; 227 21); text = 'שתפו ודווחו לקיר שלנו, עד...'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; tag = 31; layer = <CALayer: 0x12a40f20>>
| | | | | | | | | | | | <UILabel: 0x12a41f50; frame = (15 0; 290 62.5); text = ' '; userInteractionEnabled = NO; layer = <CALayer: 0x12a42000>>
| | | | | | | | | | | <_UITableViewCellSeparatorView: 0x12a41570; frame = (15 62.5; 305 0.5); layer = <CALayer: 0xd0b0f80>>
| | | | | | | | | <UITableViewCell: 0x12a3cc40; frame = (0 126; 320 63); text = ' '; autoresize = W; tag = 2; layer = <CALayer: 0x12a3cdd0>>
| | | | | | | | | | <UITableViewCellScrollView: 0x12a3d780; frame = (0 0; 320 63); autoresize = W+H; gestureRecognizers = <NSArray: 0x12a3da10>; layer = <CALayer: 0x12a3d950>; contentOffset: 0, 0>
| | | | | | | | | | | <_UITableViewCellSeparatorView: 0x12a3d690; frame = (15 62; 305 1); layer = <CALayer: 0xd0984e0>>
| | | | | | | | | | | <UITableViewCellContentView: 0x12a3ce00; frame = (0 0; 320 62.5); opaque = NO; gestureRecognizers = <NSArray: 0x12a3dcd0>; layer = <CALayer: 0x12a3ce70>>
| | | | | | | | | | | | <UIImageView: 0x12a3cea0; frame = (9 8; 45 45); clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; tag = 32; layer = <CALayer: 0x12a3cf20>>
| | | | | | | | | | | | <UILabel: 0x12a3cf50; frame = (73 -15; 227 21); text = ''; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; tag = 30; layer = <CALayer: 0x12a3d000>>
| | | | | | | | | | | | <UILabel: 0x12a3d320; frame = (73 37; 227 21); text = 'הוסיפו את גלאי מכמונות סל...'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; tag = 31; layer = <CALayer: 0x12a3d3d0>>
| | | | | | | | | | | | <UILabel: 0x12a3e4b0; frame = (15 0; 290 62.5); text = ' '; userInteractionEnabled = NO; layer = <CALayer: 0x12a3e560>>
| | | | | | | | | | | <_UITableViewCellSeparatorView: 0x12a3d200; frame = (15 62.5; 305 0.5); layer = <CALayer: 0xd0ae1b0>>
| | | | | | | | | <UITableViewCell: 0x12a39020; frame = (0 63; 320 63); text = 'גלאי מכמונות סלולארי'; autoresize = W; tag = 1; layer = <CALayer: 0x12a391b0>>
| | | | | | | | | | <UITableViewCellScrollView: 0x12a399f0; frame = (0 0; 320 63); autoresize = W+H; gestureRecognizers = <NSArray: 0xd016a50>; layer = <CALayer: 0xd0166e0>; contentOffset: 0, 0>
| | | | | | | | | | | <_UITableViewCellSeparatorView: 0xd0168a0; frame = (15 62; 305 1); layer = <CALayer: 0xd016990>>
| | | | | | | | | | | <UITableViewCellContentView: 0x12a39260; frame = (0 0; 320 62.5); opaque = NO; gestureRecognizers = <NSArray: 0x12a3a040>; layer = <CALayer: 0x12a392d0>>
| | | | | | | | | | | | <UIImageView: 0x12a39300; frame = (9 8; 45 45); clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; tag = 32; layer = <CALayer: 0x12a39380>>
| | | | | | | | | | | | <UILabel: 0x12a393b0; frame = (73 -15; 227 21); text = ''; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; tag = 30; layer = <CALayer: 0x12a39460>>
| | | | | | | | | | | | <UILabel: 0x12a39780; frame = (73 37; 227 21); text = 'אפליקציית גלאי מכמונות מה...'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; tag = 31; layer = <CALayer: 0x12a39830>>
| | | | | | | | | | | | <UILabel: 0x12a3a960; frame = (15 0; 290 62.5); text = 'גלאי מכמונות סלולארי'; userInteractionEnabled = NO; layer = <CALayer: 0x12a3aa10>>
| | | | | | | | | | | <_UITableViewCellSeparatorView: 0x12a39660; frame = (15 62.5; 305 0.5); layer = <CALayer: 0xd016550>>
| | | | | | | | | <UITableViewCell: 0xd57b950; frame = (0 0; 320 63); text = 'בוקר טוב'; autoresize = W; layer = <CALayer: 0xd57b5e0>>
| | | | | | | | | | <UITableViewCellScrollView: 0xd57c860; frame = (0 0; 320 63); autoresize = W+H; gestureRecognizers = <NSArray: 0xd57ce10>; layer = <CALayer: 0xd57cad0>; contentOffset: 0, 0>
| | | | | | | | | | | <_UITableViewCellSeparatorView: 0xd57c3f0; frame = (15 62; 305 1); layer = <CALayer: 0xd57c500>>
| | | | | | | | | | | <UITableViewCellContentView: 0xd57bd60; frame = (0 0; 320 62.5); opaque = NO; gestureRecognizers = <NSArray: 0xd081600>; layer = <CALayer: 0xd57be50>>
| | | | | | | | | | | | <UIImageView: 0xd57c000; frame = (9 8; 45 45); clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; tag = 32; layer = <CALayer: 0xd57c080>>
| | | | | | | | | | | | <UILabel: 0xd57c0b0; frame = (73 -15; 227 21); text = ''; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; tag = 30; layer = <CALayer: 0xd57b0d0>>
| | | | | | | | | | | | <UILabel: 0xd57c1c0; frame = (73 37; 227 21); text = 'יום טוב עם מלא הצלחה'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; tag = 31; layer = <CALayer: 0xd57c270>>
| | | | | | | | | | | | <UILabel: 0x12a36bc0; frame = (15 0; 290 62.5); text = 'בוקר טוב'; userInteractionEnabled = NO; layer = <CALayer: 0x12a36c70>>
| | | | | | | | | | | <_UITableViewCellSeparatorView: 0xd0afae0; frame = (15 62.5; 305 0.5); layer = <CALayer: 0x12a44b50>>
| | | | | | | | <MOORefreshView: 0xd0a6ee0; frame = (0 -64; 320 64); autoresize = W; layer = <CALayer: 0xd0a7030>>
| | | | | | | | | <UIActivityIndicatorView: 0xd0a8100; frame = (20 22; 20 20); hidden = YES; layer = <CALayer: 0xd0a81b0>>
| | | | | | | | | | <UIImageView: 0xd0a8260; frame = (0 0; 20 20); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xd0a82e0>>
| | | | | | | | | <UIImageView: 0xd0adc90; frame = (17 7; 26 50); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xd124eb0>>
| | | | | | | | | <UILabel: 0xd12a910; frame = (107 23; 106 18); text = 'Pull to refresh...'; userInteractionEnabled = NO; layer = <CALayer: 0xd124d00>>
| | | | | | | | <UIImageView: 0xd578d70; frame = (0 373.5; 320 3.5); alpha = 0; opaque = NO; autoresize = TM; userInteractionEnabled = NO; layer = <CALayer: 0xd578e40>>
| | | | | | | | <UIImageView: 0xd578f80; frame = (316.5 370; 3.5 7); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = <CALayer: 0xd579050>>
| | | | | | | <UIImageView: 0xd12abd0; frame = (10 141; 40 40); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0xd12b450>>
| | | | | | | <UIImageView: 0xd0998a0; frame = (255 75; 45 45); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0xd099830>>
| | | | | | | <UIImageView: 0xd098320; frame = (255 75; 45 45); userInteractionEnabled = NO; layer = <CALayer: 0xd0983a0>>
| | | | | | | <UILabel: 0xd129fa0; frame = (58 153; 242 21); text = 'You are part of 16 regist...'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0xd12a050>>
| | | | | | | <UILabel: 0xd283e40; frame = (0 190; 320 1); text = ''; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0xd239dc0>>
| | | | <UINavigationBar: 0xd090a20; frame = (0 20; 320 44); opaque = NO; autoresize = W; gestureRecognizers = <NSArray: 0xd091020>; layer = <CALayer: 0xd08fb70>>
| | | | | <_UINavigationBarBackground: 0xd090ae0; frame = (0 -20; 320 64); opaque = NO; autoresize = W; userInteractionEnabled = NO; layer = <CALayer: 0xd0896a0>>
| | | | | | <_UIBackdropView: 0xd099d60; frame = (0 0; 320 64); opaque = NO; autoresize = W+H; userInteractionEnabled = NO; layer = <_UIBackdropViewLayer: 0xd090440>>
| | | | | | | <_UIBackdropEffectView: 0xd059680; frame = (0 0; 320 64); clipsToBounds = YES; opaque = NO; autoresize = W+H; userInteractionEnabled = NO; layer = <CABackdropLayer: 0xd07a6c0>>
| | | | | | | <UIView: 0xd088560; frame = (0 0; 320 64); hidden = YES; opaque = NO; autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0xd07c130>>
| | | | | | | <UIView: 0xd055ec0; frame = (0 0; 320 64); alpha = 0.85; hidden = YES; opaque = NO; autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0xd028480>>
| | | | | | <UIImageView: 0xd090b80; frame = (0 64; 320 0.5); userInteractionEnabled = NO; layer = <CALayer: 0xd089460>>
| | | | | <UINavigationItemView: 0xd09aae0; frame = (136 8; 48.5 27); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xd0a1c30>>
| | | | | | <UILabel: 0xd0a1e70; frame = (0 2.5; 48.5 22); text = 'Home'; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xd0a1de0>>
| | | | | <UINavigationButton: 0xd285900; frame = (5 1; 62 40); opaque = NO; layer = <CALayer: 0xd089430>>
| | | | | | <UIImageView: 0xd0a3cc0; frame = (11 0; 40 40); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xd0a4fc0>>
| | | | | <_UINavigationBarBackIndicatorView: 0xd091120; frame = (8 12; 12.5 20.5); alpha = 0; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xd091220>>
| <TrapAlarm: 0xd07c8f0; frame = (0 0; 320 568); autoresize = LM+RM+TM+BM; layer = <CALayer: 0xd028b40>>
| | <UIToolbar: 0x12a1d640; frame = (0 0; 320 568); autoresize = LM+RM+TM+BM; layer = <CALayer: 0xd0aed00>>
| | | <_UIToolbarBackground: 0xd294410; frame = (0 0; 320 568); userInteractionEnabled = NO; layer = <CALayer: 0xd2944a0>>
| | | | <_UIBackdropView: 0xd2945e0; frame = (0 0; 320 568); opaque = NO; autoresize = W+H; userInteractionEnabled = NO; layer = <_UIBackdropViewLayer: 0xd2950f0>>
| | | | | <_UIBackdropEffectView: 0xd27daf0; frame = (0 0; 320 568); clipsToBounds = YES; opaque = NO; autoresize = W+H; userInteractionEnabled = NO; layer = <CABackdropLayer: 0xd27db60>>
| | | | | <UIView: 0xd27db90; frame = (0 0; 320 568); hidden = YES; opaque = NO; autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0xd27dbf0>>
| | | <UIImageView: 0x1296bee0; frame = (0 -0.5; 320 0.5); autoresize = W+BM; userInteractionEnabled = NO; layer = <CALayer: 0x1296beb0>>
| | <UIView: 0xd0bdcb0; frame = (0 0; 320 568); autoresize = LM+RM+TM+BM; layer = <CALayer: 0xd00cb10>>
| | | <UIImageView: 0xd0b8930; frame = (0 0; 320 568); opaque = NO; autoresize = LM+RM+TM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x12a49350>>
| | | <UIImageView: 0xd03c7f0; frame = (25 25; 265 128); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xd28fed0>>
| | | <UILabel: 0x1296e330; frame = (27 27; 265 55); text = '190 Meters'; userInteractionEnabled = NO; layer = <CALayer: 0x12957000>>
| | | <UILabel: 0x12967d00; frame = (27 87; 265 32); text = '1 הדסה 90 ב"ש'; userInteractionEnabled = NO; layer = <CALayer: 0xd26c580>>
| | | <UILabel: 0x1296d3e0; frame = (27 117; 265 32); text = 'Netroads Pilot'; userInteractionEnabled = NO; layer = <CALayer: 0xd242de0>>
| | | <UIButton: 0xd12edc0; frame = (290 20; 30 30); opaque = NO; layer = <CALayer: 0xd137d00>>
| | | | <UIImageView: 0xd293cb0; frame = (0 0; 30 30); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xd293d30>>
| | | <UIButton: 0x129668e0; frame = (27 440; 120 35); hidden = YES; opaque = NO; layer = <CALayer: 0xd2168d0>>
| | | | <UIImageView: 0xd272a70; frame = (0 0; 120 35); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xd2867d0>>
| | | | <UIButtonLabel: 0x129666e0; frame = (19 6; 81 22); text = 'Not exists'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xd2fbce0>>
| | | <UIButton: 0xd084ec0; frame = (160 440; 120 35); hidden = YES; opaque = NO; layer = <CALayer: 0xd008230>>
| | | | <UIImageView: 0xd284600; frame = (0 0; 120 35); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1293a970>>
| | | | <UIButtonLabel: 0x1296bb10; frame = (36 6; 48 22); text = 'Exists'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1296bbc0>>
(lldb)
UPDATE-3:
我最终将 UIView 转换为 UIViewController 并通过以下方式显示它:
appDelegate.window.rootViewController = testViewController;
[appDelegate.window makeKeyAndVisible];
并通过推回原来的 viewController 来解除它。
【问题讨论】:
你能改行吗[[UIApplication sharedApplication].keyWindow addSubview:trapAlarmActivity];作为 [[[UIApplication sharedApplication]delegate].window addSubview:trapAlarmActivity] 并尝试? 这是在哪个线程上运行的? @jai 我将子视图添加到 appDelegate.window 但它无济于事,因为我没有在“didFinishLaunchingWithOptions”中使用 appDelegate.window。 @JefferyThomas 我正在通过“dispatch_async()”在主线程上运行它。 作为一方,不要使用arc4random()%100
使用arc4random_uniform(100)
见arc4random(3)
【参考方案1】:
当您想要调整视图的子视图的布局时,请在应用程序的主线程上调用 setNeedsDisplay
方法。
【讨论】:
这就是我在结尾“[self setNeedsDisplay];”之前所做的。 你试过这个 setNeedsUpdateConstraints 是的,我做了,仍然没有。以上是关于UIWindow 在 addSubview 之后不更新子视图的主要内容,如果未能解决你的问题,请参考以下文章