0

Landscapeandモードで表示する必要がある画像の配列がありportraitます。私が行ったことは、画像の配列を作成し、scrollView に表示して一度に 1 つずつ表示することです。Landscape to portraitまたはその逆 画像が分割される ...ビューには前の画像の半分と次の半分が表示されます..これは毎回発生するわけではありません...画像が分割され、正確に半分に分割されない理由がわかりません...時々別の画像に分割されます サイズ..

#define portrait_width1 600.0
#define portrait_height1 600.0
#define landscape_width1 800.0
#define landscape_height1 445.0

 CGFloat kScrollObjHeight_por1 = portrait_height1;
CGFloat kScrollObjWidth_por1    = portrait_width1;

- (void)viewDidLoad{
scrollView1.indicatorStyle = UIScrollViewIndicatorStyleWhite;
    scrollView1.clipsToBounds = YES;
    // default is NO, we want to restrict drawing within our scrollview
    scrollView1.scrollEnabled = YES;
    scrollView1.delegate = self;
    scrollView1.pagingEnabled = YES;
    [scrollView1 setShowsHorizontalScrollIndicator:NO];
    [scrollView1 setShowsVerticalScrollIndicator:NO];
   kNumImages=content.count;
      for (i = 1; i <= content.count; i++)
    {

        NSArray *photos = [NSArray arrayWithObjects:


                            [UIImage imageNamed:@"c.jpg"],
                            [UIImage imageNamed:@"photo2m.jpg"],[UIImage imageNamed:@"photo1m.jpg"],[UIImage imageNamed:@"photo4m.jpg"],[UIImage imageNamed:@"photo2l.jpg"],[UIImage imageNamed:@"photo4l.jpg"],
                            nil] ;

        UIImage *image = [photos objectAtIndex:i];

        UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

        CGRect rect = imageView.frame;
        rect.size.height = kScrollObjHeight_por1;
        rect.size.width = kScrollObjWidth_por1;
        rect.origin.y=scrollView1.frame.origin.y;
        imageView.frame = rect;
        imageView.tag = i;


        [scrollArray addObject:imageView];
        [scrollView1 addSubview:imageView];
        [imageNameArray addObject:[[content objectAtIndex:i-1] _image_url]];

    }

    [self layoutScrollImages];
}
}


 -(void)layoutScrollImages
 {
 @try {
    UIImageView *view = nil;
    NSArray *subviews = [scrollView1 subviews];

        // reposition all image subviews in a horizontal serial fashion
    CGFloat curXLoc = 0;
    CGRect frame;
    for (view in subviews)
    {
        if ([view isKindOfClass:[UIImageView class]] && view.tag > 0)
        {
            frame = view.frame;
            frame.origin = CGPointMake(curXLoc, 0);
            view.frame = frame;

            curXLoc += (kScrollObjWidth_por1);
        }
    }

        // set the content size so it can be scrollable
    [scrollView1 setContentSize:CGSizeMake((kNumImages * kScrollObjWidth_por1), kScrollObjHeight_por1)];
        // scrollView.contentSize = CGSizeMake(scrollView.contentSize.width,scrollView.frame.size.height);
    NSLog(@"%d",[imageNameArray indexOfObject:Images]);
    currentImage=[scrollArray objectAtIndex:[imageNameArray indexOfObject:Images]];

    [scrollView1 scrollRectToVisible:currentImage.frame animated:YES];
}
@catch (NSException *exception) {
    NSLog(@"ImageFullScreenViewController - layoutScrollImages Exception Name = %@ Exception Reason = %@",[exception name],[exception reason]);
}


}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}

 - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

@try {
    if ([UIDevice currentDevice].orientation== UIInterfaceOrientationLandscapeLeft || [UIDevice currentDevice].orientation  == UIInterfaceOrientationLandscapeRight)
    {
        if (!landscapeImgSCRf) {
            CGFloat curXLoc = 0;
            CGRect frame;
            for (UIView *subview in scrollView1.subviews)
            {


                if ([subview isKindOfClass:[UIImageView class]])
                {
                    if (!rightside2f) {
                        kScrollObjWidth_por1 = landscape_width1;
                        kScrollObjHeight_por1= landscape_height1;
                        curXLoc = subview.frame.origin.x;
                        rightside2f=YES;

                    }
                    frame.origin = CGPointMake(curXLoc, 0);
                    [subview setFrame: CGRectMake(curXLoc, subview.frame.origin.y, kScrollObjWidth_por1, kScrollObjHeight_por1)];
                    curXLoc += (kScrollObjWidth_por1);
                    scrollView1.frame=CGRectMake(scrollView1.frame.origin.x, scrollView1.frame.origin.y, scrollView1.frame.size.width, scrollView1.frame.size.height);

                }


            }


            [scrollView1 setContentSize:CGSizeMake((kNumImages * kScrollObjWidth_por1), kScrollObjHeight_por1)];
            landscapeImgSCRf=YES;
        }

    }else
    {
        if (landscapeImgSCRf) {
            CGFloat curXLoc = 0;
            CGRect frame;
            for (UIView *subview in scrollView1.subviews)
            {


                if ([subview isKindOfClass:[UIImageView class]])
                {
                    if (rightside2f) {
                        kScrollObjWidth_por1 = portrait_width1;
                        kScrollObjHeight_por1= portrait_height1;
                        curXLoc = subview.frame.origin.x;
                        rightside2f=NO;

                    }
                    frame.origin = CGPointMake(curXLoc, 0);
                    [subview setFrame: CGRectMake(curXLoc, subview.frame.origin.y, kScrollObjWidth_por1, kScrollObjHeight_por1)];
                    curXLoc += (kScrollObjWidth_por1);
                    scrollView1.frame=CGRectMake(scrollView1.frame.origin.x, scrollView1.frame.origin.y, scrollView1.frame.size.width, scrollView1.frame.size.height);
                }


            }
            landscapeImgSCRf=NO;
            [scrollView1 setContentSize:CGSizeMake((kNumImages * kScrollObjWidth_por1), kScrollObjHeight_por1)];


        }

    }

}
@catch (NSException *exception) {
    NSLog(@"ImageFullScreenViewController - willRotateToInterfaceOrientation Exception Name = %@ Exception Reason = %@",[exception name],[exception reason]);
}



 }

画像をチェック

4

0 に答える 0