- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientat ion duration:(NSTimeInterval)duration {
UIInterfaceOrientation o = self.interfaceOrientation;
if ((o == UIInterfaceOrientationPortrait) || (o == UIInterfaceOrientationPortraitUpsideDown)) {D = 1;[self setPaging];}
if ((o == UIInterfaceOrientationLandscapeLeft) || (o == UIInterfaceOrientationLandscapeRight)) {D = 2;[self setPaging];}}
Я дублирую некоторые из моих методов, чтобы у меня был один вид для портрета и другой вид для ландшафтного режима.В основном это работает, например:
//-----------------------------------------------------------------------------*
-(ImageScrollView*)imagescrollview{
if(imagescrollview == nil){
imagescrollview = [[viewClass alloc] initWithFrame:CGRectZero];}
return imagescrollview;}
//--*duplicate
-(ImageScrollView2*)imagescrollview2{
if(imagescrollview2 == nil){
imagescrollview2 = [[viewClass alloc] initWithFrame:CGRectZero];}
return imagescrollview2;}
//-----------------------------------------------------------------------------*
- (ImageScrollView *)dequeueRecycledPage{
ImageScrollView *page = [recycledPages anyObject];
if (page) {
[[page retain] autorelease];
[recycledPages removeObject:page];}
return page;}
//--*duplicate
- (ImageScrollView2 *)dequeueRecycledPage2{
ImageScrollView2 *page = [recycledPages anyObject];
if (page) {
[[page retain] autorelease];
[recycledPages removeObject:page];}
return page;}
Код выше (мой дублированный метод) работает!Но приведенный ниже код вызывает сбой приложения ...
//-----------------------------------------------------------------------------*
- (void)tilePages {
if (D == 1) {
// Calculate which pages are visible
CGRect visibleBounds = pagingScrollView.bounds;
int firstNeededPageIndex = floorf(CGRectGetMinX(visibleBounds) / CGRectGetWidth(visibleBounds));
int lastNeededPageIndex = floorf((CGRectGetMaxX(visibleBounds)-1) / CGRectGetWidth(visibleBounds));
firstNeededPageIndex = MAX(firstNeededPageIndex, 0);
lastNeededPageIndex = MIN(lastNeededPageIndex, [self pdfPageCount] - 1);
// Recycle no-longer-visible pages
for (ImageScrollView *page in visiblePages) {
if (page.index < firstNeededPageIndex || page.index > lastNeededPageIndex) {
[recycledPages addObject:page];
[page removeFromSuperview];}}
[visiblePages minusSet:recycledPages];
// add missing pages
for (int index = firstNeededPageIndex; index <= lastNeededPageIndex; index++) {
if (![self isDisplayingPageForIndex:index]) {
ImageScrollView *page = [self dequeueRecycledPage];
if (page == nil) {
page = [[[ImageScrollView alloc] init] autorelease];}
[self configurePage:page forIndex:index];
[pagingScrollView addSubview:page];
[visiblePages addObject:page];}}}
else if (D == 2) {
// Calculate which pages are visible
CGRect visibleBounds = pagingScrollView.bounds;
int firstNeededPageIndex = floorf(CGRectGetMinX(visibleBounds) / CGRectGetWidth(visibleBounds));
int lastNeededPageIndex = floorf((CGRectGetMaxX(visibleBounds)-1) / CGRectGetWidth(visibleBounds));
firstNeededPageIndex = MAX(firstNeededPageIndex, 0);
lastNeededPageIndex = MIN(lastNeededPageIndex, [self pdfPageCount] - 1);
// Recycle no-longer-visible pages
for (ImageScrollView2 *page in visiblePages) {
if (page.index2 < firstNeededPageIndex || page.index2 > lastNeededPageIndex) {
[recycledPages addObject:page];
[page removeFromSuperview];}}
[visiblePages minusSet:recycledPages];
// add missing pages
for (int index = firstNeededPageIndex; index <= lastNeededPageIndex; index++) {
if (![self isDisplayingPageForIndex:index]) {
ImageScrollView2 *page = [self dequeueRecycledPage2];
if (page == nil) {
page = [[[ImageScrollView2 alloc] init] autorelease];}
[self configurePage2:page forIndex2:index];
[pagingScrollView addSubview:page];
[visiblePages addObject:page];}}}}
//-----------------------------------------------------------------------------*
- (void)configurePage:(ImageScrollView *)page forIndex:(NSUInteger)index{
page.index = index;
page.frame = [self frameForPageAtIndex:index];
[page displayTiledImageNamed:[self pdfPage: index] size:[self pdfSize: index]];}
//--*duplicate
- (void)configurePage2:(ImageScrollView2 *)page forIndex2:(NSUInteger) index {NSLog(@"1");
page.index2 = index;NSLog(@"4");
page.frame = [self frameForPageAtIndex:index];NSLog(@"5");
[page displayTiledImageNamed2:[self pdfPage: index] size:[self pdfSize: index]];NSLog(@"6");}
сбой связан с index2 (index2 является дубликатом индекса), см. Здесь:
//-----------------------------------------------------------------------------*
@interface ImageScrollView : UIScrollView <UIScrollViewDelegate> {
UIView *imageView;
NSUInteger index;
}
@property (assign) NSUInteger index;
- (void)displayTiledImageNamed:(CGPDFPageRef)page size:(CGSize)imageSize;
@end
//--*duplicate
@interface ImageScrollView2 : UIScrollView <UIScrollViewDelegate> {
UIView *imageView;
NSUInteger index2;
}
@property (assign) NSUInteger index2;
- (void)displayTiledImageNamed2:(CGPDFPageRef)page size:(CGSize)imageSize;
@end
Ошибка в консоли:
2010-08-22 03:02:36.532 PDFmag[31408:207] p4
2010-08-22 03:02:36.541 PDFmag[31408:207] *** -[ImageScrollView index2]: unrecognized selector sent to instance 0x148d10
2010-08-22 03:02:36.551 PDFmag[31408:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[ImageScrollView index2]: unrecognized selector sent to instance 0x148d10'
2010-08-22 03:02:36.565 PDFmag[31408:207] Stack: (
864992541,
859229716,
864996349,
864492313,
864454720,
21249,
18449,
21417,
838908048,
839266120,
839260480,
864766485,
839108308,
839107980,
839226672,
839225216,
839206800,
839205012,
875886564,
864740651,
864738335,
875880904,
838872112,
838865456,
11645,
11560
)
terminate called after throwing an instance of 'NSException'
Program received signal: “SIGABRT”.
NSLog (@ "p4");приложение выглядит так, как будто оно падает здесь !!Я не уверен, что случилось с этим, пожалуйста, сообщите мне.
Спасибо.