5

我是 iPad 开发者的新手,

我在我的应用程序中制作了一个注册表单,当我在模式下看到我的应用程序时Portrait,我可以看到整个表单没有滚动,但是当我在Landscape模式下看到相同的表单时,我看不到页面底部的部分,因为滚动应该在那里看到底部。

s.h当我替换时在我的文件中

@interface ReminderPage : UIViewController{
...
...
}

:UIViewController:UIScrollView

然后当我.m像这样在我的文件中添加标签时,

UILabel *Lastpaidlbl = [[[UILabel alloc] initWithFrame:CGRectMake(70 ,400, 130, 50)]autorelease];
    Lastpaidlbl.backgroundColor = [UIColor greenColor];
    Lastpaidlbl.font=[UIFont systemFontOfSize:20];
    Lastpaidlbl.text = @"Lastpaid on :";
    [self.view addSubview:Lastpaidlbl];

我在类名类型的对象上找不到最后一行属性视图时出错。 我无法在我的视图中添加标签。

任何帮助将不胜感激。

4

5 回答 5

6

这个问题似乎真的是在问如何将屏幕上的所有组件放置在 UIScrollView 中,而不是 UIView 中。使用 Xcode 4.6.3,我发现我可以通过简单地实现这一点:

  • 在 Interface Builder 中,选择主 UIView 内的所有子视图。
  • 选择 Xcode 菜单项“编辑器|嵌入|滚动视图”。

最终结果是在现有的主 UIView 中嵌入了一个新的滚动视图,UIView 的所有以前的子视图现在都作为 UIScrollView 的子视图,具有相同的定位。

于 2013-09-19T12:48:08.147 回答
4

如果你想用 UIScrollView 替换你的 UIViewController,你将不得不对你的代码进行一些重构。你得到的错误只是一个例子:

语法:

[self.view addSubview:Lastpaidlbl];

如果self是 UIViewController 是正确的;既然你把它改成了UIScrollView,你现在应该这样做:

[self addSubview:Lastpaidlbl];

您将对代码进行很多类似这样的更改,并且会遇到一些问题。

另一种方法是:

  1. 实例化一个 UIScrollView(不是从它派生的);

  2. 将您的 UIView(如您已定义的)添加到滚动视图;

  3. 定义contentSize滚动视图,以便包含您拥有的整个 UIView。

滚动视图充当现有视图的容器(您将控件添加到滚动视图,然后将滚动视图添加到 self.view);这样,您可以将其集成到现有控制器中:

      1. UIScrollView* scrollView = <alloc/init>

      2. [self.view addSubview:scrollView]; (in your  controller)

      3. [scrollView addSubview:<label>]; (for all of your labels and fields).

      4. scrollView.contentSize = xxx;

我认为后一种方法会容易得多。

于 2012-07-06T07:26:02.043 回答
0

请将您所有的 UIComponents 放到 UIScrollview 中,然后它将开始滚动。

请查看内容大小。请根据设备的方向进行更改。

于 2012-07-06T07:16:29.833 回答
0

你是子类化UIScrollView,所以没有,self.view因为已经self是(滚动视图的)视图。您不需要子类化滚动视图,您可以将组件嵌入到 ivar 滚动视图中并设置它contentSize(在您的情况下,您必须在设备处于横向模式时启用滚动)。在界面生成器中,您可以一键嵌入所选元素,编辑器->嵌入->滚动视图。

于 2012-07-06T07:24:55.197 回答
0

首先创建滚动视图

 UIScrollView *  scr=[[UIScrollView alloc] initWithFrame:CGRectMake(10, 70, 756, 1000)];
    scr.backgroundColor=[UIColor clearColor];
    [ self.view addSubview:scr];

第二

改变 [self.view addSubview:Lastpaidlbl];

      to

[scr addSubview:Lastpaidlbl];

第三

设置高度取决于内容

UIView *view = nil;

 NSArray *subviews = [scr subviews];


 CGFloat curXLoc = 0;

    for (view in subviews)
    {
        CGRect frame = view.frame;
        curXLoc += (frame.size.height);
    }
       // set the content size so it can be scrollable
    [scr setContentSize:CGSizeMake(756, curXLoc)];

最后

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Override to allow orientations other than the default portrait orientation.
    if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft || interfaceOrientation==UIInterfaceOrientationLandscapeRight) {
        self.scr.frame = CGRectMake(0, 0, 703,768);    

        } else {
        self.scr.frame = CGRectMake(0, 0, 768, 1024);
        }


    return YES;
}
于 2012-07-06T07:40:43.800 回答