使用下面的代码在旋转之前转储 self.view 的超级视图和子视图,然后在旋转完成后,然后在旋转回纵向完成后再次转储。其中一个视图与其原始来源不匹配,这将是您的问题视图。原点的变化很可能是由于没有在顶部/左侧启用支柱。
这发生在我身上很多次,我写了这个 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