Objective c 我希望当方向发生在横向模式时,presentview及其内容在滚动视图上

Objective c 我希望当方向发生在横向模式时,presentview及其内容在滚动视图上,objective-c,ios6,uiscrollview,xcode4.5,Objective C,Ios6,Uiscrollview,Xcode4.5,当我从纵向模式切换到横向模式时,视图应广泛扩展,但长度应相同,并且在scrollview中,因此当我滚动时,应显示完整内容: if (([[UIDevice currentDevice]orientation] == UIInterfaceOrientationLandscapeLeft) || ([[UIDevice currentDevice]orientation] == UIInterfaceOrientationLandscapeRight)) { UIScrollVi

当我从纵向模式切换到横向模式时,视图应广泛扩展,但长度应相同,并且在scrollview中,因此当我滚动时,应显示完整内容:

if (([[UIDevice currentDevice]orientation] == UIInterfaceOrientationLandscapeLeft) ||
    ([[UIDevice currentDevice]orientation] == UIInterfaceOrientationLandscapeRight))
{
    UIScrollView *scrollView=[[UIScrollView alloc] init];
    UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 480, 480)];
    view1 = self.view;
    [scrollView addSubview:view1];
    scrollView.frame = CGRectMake(0, 0, 480, 480);
    scrollView.contentSize = CGSizeMake(480, 480);
    scrollView.delegate = self;
    scrollView.alwaysBounceVertical = YES;
    [self.view addSubview:scrollView];
}

请用更多信息更新您的问题,例如-什么是有效的,什么是无效的?不要将更新添加为评论,编辑您的问题

在您现有的代码中,至少这是错误的/混乱的:

 UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 480, 480)];
 view1 = self.view;
您将在第一行中为新视图指定指针,然后在第二行中将其重新指定给现有的self.view。那么这里:

    [self.view addSubview:scrollView];
您正在将包含内容视图的滚动视图添加到同一内容视图中。那是行不通的

作为一个更简洁的解决方案,为什么不为两个方向设置scrollview/subview组合呢。然后,当您旋转时,您只需要更改scrollview的contentsize

对于正常垂直方向:

            self.scrollview.contentSize = self.scrollview.bounds.size;
对于景观:

              self.scrollview.contentSize =
         CGSizeMake(self.scrollView.bounds.size.width, self.contentView.bounds.size.height 
(假设您的内容位于scrollView中包含的名为contentView的视图中)


您应该能够使
contentOffset
在故事板中的两个方向都能正常工作,但如果不能,您可以在代码中为每个方向设置它

任何人都可以发送它的代码Google it,在询问之前尝试一些东西我已经尝试过了,但无法扩展视图并显示它…显示您尝试过的代码。如果([[UIDevice currentDevice]orientation]==UIInterfaceOrientationAndscapeLeft)|([[UIDevice currentDevice]orientation]==UIInterfaceOrientationAndscapeRight)){UIScrollView*scrollView=[[UIScrollView alloc]init];UIView*view1=[[UIView alloc]initWithFrame:CGRectMake(0,0,480,480)];view1=self.view;[scrollView addSubview:view1];scrollView.frame=CGRectMake(0,0,480,480);scrollView.contentSize=CGSizeMake(480,480);scrollView.delegate=self;scrollView.alwaysBounceVertical=YES;[self.view addSubview:scrollView];}
if(([[UIDevice currentDevice]orientation] == UIInterfaceOrientationLandscapeLeft) || ([[UIDevice currentDevice]orientation] == UIInterfaceOrientationLandscapeRight)) { 
UIScrollView * scrollView=[[UIScrollView alloc] init]; UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 480, 480)]; 
view1 = self.view; [scrollView addSubview:view1]; scrollView.frame = CGRectMake(0, 0, 480, 480);           
scrollView.contentSize = CGSizeMake(480, 480); scrollView.delegate = self; 
scrollView.alwaysBounceVertical = YES; [self.view addSubview:scrollView]; 
}