【问题标题】:I want the presentview and its contents to be on scroll view when orientation occurs to landscape mode当方向发生在横向模式时,我希望 presentview 及其内容在滚动视图上
【发布时间】:2013-01-29 10:27:04
【问题描述】:

当我从纵向模式切换到横向模式时,视图应该扩大,但长度应该相同并且在滚动视图中,这样当我滚动时应该显示全部内容:

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];
}

【问题讨论】:

  • 任何人都可以发送代码
  • 谷歌一下,问之前先试一下
  • 我试过了,但无法展开视图并显示它...
  • 显示您尝试过的代码。
  • 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 = 自我; scrollView.alwaysBounceVertical = YES; [self.view addSubview:scrollView]; }

标签: objective-c ios6 uiscrollview xcode4.5


【解决方案1】:
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]; 
}

【讨论】:

    【解决方案2】:

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

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

     UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 480, 480)];
     view1 = self.view;
    

    您在第一行分配一个指向新视图的指针,然后在第二行将其重新分配给您现有的 self.view。那么这里:

        [self.view addSubview:scrollView];
    

    您正在向同一内容视图添加包含内容视图的滚动视图。那是行不通的。

    作为一种更简洁的解决方案,为什么不为 both 方向设置滚动视图/子视图组合。然后当你旋转时,你只需要改变你的滚动视图的内容大小。

    对于正常的直立方向:

                self.scrollview.contentSize = self.scrollview.bounds.size;
    

    横向:

                  self.scrollview.contentSize =
             CGSizeMake(self.scrollView.bounds.size.width, self.contentView.bounds.size.height 
    

    (假设您的内容位于 scrollView 内的名为 contentView 的视图中)

    您应该能够让contentOffset 在情节提要中的两个方向上正常工作,但如果不是,您可以在代码中为每个方向设置它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-12
      • 2018-08-13
      • 1970-01-01
      • 2020-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多