1

滚动视图显示,没有任何可见的视图。视图移动正常,页面控件正常工作。当我更改滚动条背景时,一切正常。没有显示“不同颜色”的视图。不知道出了什么问题。谢谢您的帮助

-(void)viewDidLoad {    
[super viewDidLoad];

CGRect frame = CGRectMake(0, 215, WIDTH_OF_IPHONE, HEIGHT_OF_SCROLLER);

int numOfPhotos = 6;

scrollViewer = [[UIScrollView alloc] initWithFrame:frame];
scrollViewer.contentSize = CGSizeMake((WIDTH_OF_IPHONE*numOfPhotos), HEIGHT_OF_SCROLLER);
scrollViewer.pagingEnabled = YES;
//scrollViewer.backgroundColor = [UIColor lightGrayColor];
[scrollViewer setDelegate:self];

int i = 0;

while (i < numOfPhotos){

    CGRect frameOfView = CGRectMake((i*320), 215, 320, HEIGHT_OF_SCROLLER);
    UIView *photoFrame = [[UIView alloc] initWithFrame:frameOfView];

    if (i == 0){
        photoFrame.backgroundColor = [UIColor redColor];//colorWithPatternImage:image1];
        NSLog(@"colour was selected");
    }else if (i==1){
        photoFrame.backgroundColor = [UIColor blueColor];//colorWithPatternImage:image2];
    }else if (i==2){
        photoFrame.backgroundColor = [UIColor purpleColor];//colorWithPatternImage:image3];
    }else if (i==3){
        photoFrame.backgroundColor = [UIColor orangeColor];//colorWithPatternImage:image4];
    }else if (i==4){
        photoFrame.backgroundColor = [UIColor magentaColor];//colorWithPatternImage:image5];
    }else{
        photoFrame.backgroundColor = [UIColor greenColor];//colorWithPatternImage:image6];
    }

    [scrollViewer addSubview:photoFrame];
    //[photoFrame release];

    photoFrame = NULL;
    i++;
}
pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 0, WIDTH_OF_IPHONE, 15)];
pageControl.center = CGPointMake(scrollViewer.center.x, (208+HEIGHT_OF_SCROLLER));

[pageControl setNumberOfPages:numOfPhotos];

[pageControl addTarget:self action:@selector(pageSwiped:) forControlEvents:UIControlEventValueChanged];

[self.view addSubview:scrollViewer];
[self.view addSubview:pageControl];

我的 .H 文件看起来像这样

@interface HomePage : UIViewController <UIActionSheetDelegate, UIScrollViewDelegate> {

   IBOutlet UIScrollView *scrollViewer;
   UIPageControl *pageControl;
   BOOL pageControlUsed;

}
@end
4

1 回答 1

0

尝试将 photoFrame 的 y 原点设置为 0,因为它将把它放在滚动视图的实际框架下。

如果不是您遇到的问题是您将相框设置为 NULL。如果您使用 ARC,则不必担心,因为垃圾收集器会处理它。

于 2013-10-05T15:08:43.700 回答