-1

Scrollview をビューコントローラーに配置しようとしていますか? 出来ますか?また、UIViewをScrollViewに配置したいと考えています。

UIScrollView *scrollView =[[UIScrollView alloc]initWithFrame:CGRectMake(20, 60, 280, 200)];
    scrollView.contentSize = CGSizeMake(280, 200);
    scrollView.backgroundColor=[UIColor orangeColor];
    scrollView.delegate = self;
    [self.view addSubview:scrollView];

    UIView *container = [[UIView alloc] initWithFrame:CGRectMake(20, 60, 280, 200)];
    container.backgroundColor = [UIColor whiteColor];
    [scrollView addSubview:container];

このコードでは、scrollview を VC に配置しようとしましたが、View を ScrollView に配置しようとしました。

            rb1 = [[RadioButton alloc] initWithGroupId:@"first group" index:j];
            rb1.frame = CGRectMake(20,dy,22,22);
            [container addSubview:rb1];
            [rb1 release];

            label1 =[[UILabel alloc] initWithFrame:CGRectMake(50, dy, 60, 20)];
            label1.backgroundColor = [UIColor clearColor];
            label1.text = [answers objectAtIndex:j];
            [container addSubview:label1];

ここで、Viewにラジオボタンを配置しようとしました。

私はそれが明確であることを願っています:) 私の悪い英語を申し訳ありません.Thanks.

4

3 に答える 3

0

これを試して、スクロールビューをコントローラーに配置してください

#import <UIKit/UIKit.h>

@interface YourClass : UIViewController {

IBOutlet UIScrollView *scrollView;

}


@property (nonatomic, retain) UIScrollView *scrollView;

@end

v/v を入力するには、これを試してください

   NSUInteger scrollContentCount = 0;

   for (NSUInteger arrayIndex = 0; 
         arrayIndex < [contents count]; 
         arrayIndex++) {


    // set scorllview properties
    CGRect frame;
    frame.origin.x = self.mScrollView.frame.size.width * arrayIndex;
    frame.origin.y = 0;
    frame.size = self.mScrollView.frame.size;

    myScrollView.autoresizingMask = YES;

    // alloc - init PODetailsView Controller
    myController = [[MyController alloc] initWithNibName:@"MyController" bundle:[NSBundle mainBundle]];

    [myController.view setFrame:frame];

    // add view in scroll view
    [self.myScrollView addSubview:myController.view];

    scrollContentCount = scrollContentCount + 1;
}

 // set scroll content size
 self.myScrollView.contentSize = 
CGSizeMake(self.myScrollView.frame.size.width * scrollContentCount, 
                     self.myScrollView.frame.size.height);
  }
于 2013-01-24T08:14:29.047 に答える
0

ここでは、スクロール サイズと同じコンテンツ サイズを指定します。

scrollView.contentSize = CGSizeMake(280, 200);

コンテンツ サイズでは、スクロールする領域のサイズを入力する必要があります。あなたの場合、スクロール可能な領域はscrollViewのサイズと同じであるため、スクロールする必要はありません。

于 2013-01-24T08:12:37.727 に答える
0

スクロール ビューのフレームがコンテンツ サイズより小さい場合、スクロールが発生します。

フレームのサイズは (280,200) で、同じサイズを contentSize に指定しました。

スクロールを可能にするには、以下の行をコードに置き換えます。

scrollView.contentSize = CGSizeMake(300, 260);

于 2013-01-24T08:43:16.267 に答える