以下のコードを使用して、回転前に self.view のスーパービューとサブビューをダンプし、次に回転が完了した後、縦向きに戻る回転が完了したときに再びダンプします。ビューの 1 つが元の元のビューと一致せず、それが問題のビューになります。原点の変更は、上部/左側で支柱が有効になっていないことが原因である可能性があります。
これは私に何度も起こり、スーパービューとサブビューをダンプするためにこの UIView カテゴリを書きました。
使用法:
[UIView dumpSuperviews:self.view msg:@"Original superviews"];
[UIView dumpSubviews:self.view msg:@"Original subviews"];
コード:
#import <QuartzCore/QuartzCore.h>
#import "UIView+Utilities.h"
@interface UIView (Utilities_Private)
+ (void)appendView:(UIView *)v toStr:(NSMutableString *)str;
@end
@implementation UIView (Utilities_Private)
+ (void)appendView:(UIView *)a toStr:(NSMutableString *)str
{
[str appendFormat:@" %@: frame=%@ bounds=%@ layerFrame=%@ tag=%d userInteraction=%d alpha=%f hidden=%d\n",
NSStringFromClass([a class]),
NSStringFromCGRect(a.frame),
NSStringFromCGRect(a.bounds),
NSStringFromCGRect(a.layer.frame),
a.tag,
a.userInteractionEnabled,
a.alpha,
a.isHidden
];
}
@end
@implementation UIView (Utilities)
+ (void)dumpSuperviews:(UIView *)v msg:(NSString *)msg
{
NSMutableString *str = [NSMutableString stringWithCapacity:256];
while(v) {
[self appendView:v toStr:str];
v = v.superview;
}
[str appendString:@"\n"];
NSLog(@"%@:\n%@", msg, str);
}
+ (void)dumpSubviews:(UIView *)v msg:(NSString *)msg
{
NSMutableString *str = [NSMutableString stringWithCapacity:256];
if(v) [self appendView:v toStr:str];
for(UIView *a in v.subviews) {
[self appendView:a toStr:str];
}
[str appendString:@"\n"];
NSLog(@"%@:\n%@", msg, str);
}
@end