Objective c UIScrollView自定义视图旋转问题

Objective c UIScrollView自定义视图旋转问题,objective-c,uiview,uiscrollview,Objective C,Uiview,Uiscrollview,我有一个带有自定义视图的滚动视图。现在我有旋转的问题,旋转后的视图没有正确的帧位置/大小 如何在旋转后调用CustomView来重新定位和调整框架和内容的大小 - (void)setupPage { NSUInteger nimages = 0; CGFloat cx = 0; for (; ; nimages++) { if (nimages == list.count) { break; } C

我有一个带有自定义视图的滚动视图。现在我有旋转的问题,旋转后的视图没有正确的帧位置/大小

如何在旋转后调用CustomView来重新定位和调整框架和内容的大小

- (void)setupPage
{
    NSUInteger nimages = 0;
    CGFloat cx = 0;
    for (; ; nimages++) {
        if (nimages == list.count) {
            break;
        }

        CustomStepView *stepView = [[CustomStepView alloc] initWithFrame:CGRectZero];
        stepView.tag = nimages;
        if([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown) 
        {

            stepView.frame = CGRectMake(cx, 0.0 , 768.0f, 926.0f);
            cx += 768.0;
        }
        else
        {
            stepView.frame = CGRectMake(cx, 0.0 , 1024.0f, 670.0f);
            cx += 1024.0;
        }

        [scrollView addSubview:stepView];
        [stepView release];

    }

    self.pageControl.numberOfPages = nimages;

}

从外观上看,ScrollView中有很多子视图(自定义视图)

首先,不要尝试使用UIDevice检测方向,苹果不建议这样做。 为处理旋转,您提供了“shouldAutorotateToInterfaceOrientation”功能

在这个方法中,您可以简单地运行一个循环来检测scrollview中的子视图,然后设置每个子视图的框架和大小

这可能看起来像这样:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
   if(interfaceOrientation ==  UIInterfaceOrientationPortrait)
   {
     for(UIView *asubview in scrollView.subviews)
     {
        asubview.frame = "NEW FRAME";    
     }
   }
   else
   {
       asubview.frame = "NEW FRAME";
   } 
}
希望它能帮助你……虽然我知道很久以前就有人问过这个问题:-)
干杯

您不应该更改
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
中的框架。您在
-will…
-did…
方法中进行更改。