1

I have a problem with iCarousel view to resizing the item placed in carousel view during screen orientation changes.How can i fix this?

Here is my code

- ( void ) handleOrientation:(UIInterfaceOrientation )toInterfaceOrientation {

    if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {

        orient = YES;

        _deptCarousel.center = CGPointMake(390, 628);

    }else {

        orient = NO;

        _deptCarousel.center = CGPointMake(512, 455);

    }

}

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index
{

    //create a numbered view
    UIView *viewBG = nil;
    viewBG = [[UIImageView alloc]initWithImage:[UIImage imageNamed:IS_IPAD?@"Scroll_Placeholder_ImageiPad.png":@"Carousel_Placeholder_Image.png"]];
    if (IS_IPAD) {
        if (orient) {
            viewBG.frame = CGRectMake(0, 0, 420, 350);
        }else{
            viewBG.frame = CGRectMake(0, 0, 380, 280);
        }
    } else {
        viewBG.frame = CGRectMake(0, 0, 210, 170);
    }
}
4

2 回答 2

2

well for changing the frame you should reload your carousel in your Orientation method otherwise it won't effect it.

- ( void ) handleOrientation:(UIInterfaceOrientation )toInterfaceOrientation {

    if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {

        orient = YES;

        _deptCarousel.center = CGPointMake(390, 628);

        //reload your Carousel

    }else {

        orient = NO;

        _deptCarousel.center = CGPointMake(512, 455);

         //reload your Carousel


    }

}
于 2013-04-19T05:23:56.540 回答
2

I think you have checked your device orientation when the iCarousel loads for the first time.You have to check and resize your Carousel View whenever your orientation changes. So try to check it in the orientation delegate like below.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
  UIInterfaceOrientation statusBarOrientation = [[UIApplication sharedApplication] statusBarOrientation];

    if (IS_IPAD) {
       if (orient) {
            viewBG.frame = CGRectMake(0, 0, 420, 350);
         }else{
            viewBG.frame = CGRectMake(0, 0, 380, 280);
         }
    }

    [_deptCarousel reloadData];

  return YES;
}

I think it may help you. Please let me know if you have any queries in this.

Thank you.

于 2013-04-19T05:25:30.027 回答