私は、 HTML形式のテキストを表示するUIView
を含むカスタムサブクラスを持っているiPadアプリケーションに取り組んでいます(私はそれに名前を付けました)。の各ページにこれらのサブクラスのインスタンスが1つあります。ユーザーは横にスクロールしてさまざまなテキストから選択し、下にスクロールしてテキストを読みます。スクロールビューには、これらのうち10個があります。UIWebView
EssayView
UIView
UIScrollView
EssayViews
私のアプリはすべての向きをサポートする必要がありますが、ユーザーがデバイスを回転させると(横向きから縦向き、またはその逆)、メモリ警告がスローされ、アプリは通常クラッシュします。
私はいくつかのプロファイリングを行いました。iOS5を実行しているiPad3では、アプリはEssayScrollViewを表示するときに528MBの仮想メモリを消費しますが、iOS5を実行しているiPad1では193MBしか消費しません...それでも両方でクラッシュします。iOS6を実行しているiPad3では、アプリはEssayScrollViewを表示するときに640MBの仮想メモリを消費しますが、回転してもクラッシュしません。したがって、問題はiOS5を実行しているデバイスにあるようです...
EssayViewインスタンスを初期化する方法は次のとおりです。
EssayView.m
@interface EssayView()
@property UIWebView *essayWebView;
@property NSString *essayName;
@property int essayNumber;
@end
@implementation EssayView
- (id)initWithEssayNamed:(NSString *)theEssayName number:(int)theEssayNumber{
self = [super initWithFrame:CGRectMake(0,0,[[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height)];
if(self){
essayNumber = theEssayNumber;
essayName = theEssayName;
essayWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height)];
essayWebView.center = CGPointMake(self.bounds.size.width/2, essayWebView.center.y);
[essayWebView setScalesPageToFit:NO];
essayWebView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
essayWebView.delegate = self;
}
return self;
}
EssayViewsの親ビューのローテーションコードは次のとおりです。
EssayScrollView.m
- (BOOL)shouldAutorotate{
return YES;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return YES;
}
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
[super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
[scrollView setContentSize:CGSizeMake([essayArray count] * scrollView.frame.size.width, scrollView.frame.size.height)];
[scrollView setContentOffset:CGPointMake(scrollView.bounds.size.width*currentEssay, 0) animated:NO];
}
inにセットUIViewAutoresizingMasks
を割り当てた行が問題の原因になっているようです。コメントアウトすると、UIは細かくスムーズに回転します(ただし、もちろんUIWebViewは自動サイズ変更されません)。UIWebView
EssayView
iOS 5でテストすると、メモリ警告がスローされ、数秒後に回転し、クラッシュすることがよくあります。ただし、iOS6ではクラッシュしません。どちらのOSでも、回転アニメーションは通常より遅く、不格好です。
メモリの警告やクラッシュを発生させずに、複数のWebビューのサイズを変更する方法はありますか?