0

我有一个观点。UIScrollViev 在哪里水平滚动 UIImages。但在 tjis View 中仍然有很多信息,它应该向下滚动。

当我添加垂直 UiScrollView 时,我的水平 UiScrollView 不起作用......而且垂直也是......当我将它们分开时,它们都工作得很好。如何在一个视图中使用两个 uisrollview?

水平 UIScrollView 工作点:

    - (void)viewDidLoad
{
    [super viewDidLoad];

    scrolldown.delegate =self;
    [scrolldown setScrollEnabled:YES];
    [scrolldown setContentSize:CGSizeMake(320, 1000)];

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 500, 200, 30)];
    label.text=@"okdddd";
    [self->scrolldown addSubview:label];

    self.cost.text=[NSString stringWithFormat:@"%@ %@",ArrayCost[_id_item], ArrayTypeCostName[_id_item]];

    pageControlBeingUsed = NO;
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    CGFloat screenWidth = screenRect.size.width;
    CGFloat screenHight = screenRect.size.height;
    for (int i = 0; i < [ArrayImages[_id_item] count]; i++) {
        CGRect frame;
        frame.origin.x = self.scrollView.frame.size.width * i;
        frame.origin.y = 0;
        frame.size = self.scrollView.frame.size;
        NSString *val = [ArrayImages[_id_item] objectAtIndex:i];

        NSData *data = [NSData dataWithContentsOfURL: [NSURL URLWithString: val]];
        UIImage* theImage = [[UIImage alloc] initWithData:data];
        //UIImageView *img=[[UIImageView alloc] initWithFrame:CGRectMake(screenWidth*i,0,theImage.size.width ,theImage.size.height)];
        UIImageView *img=[[UIImageView alloc] initWithFrame:CGRectMake(screenWidth*i,0,screenWidth ,200)];
        img.image = theImage;
        [self.scrollView addSubview:img];
    }

    self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * [ArrayImages[_id_item] count], self.scrollView.frame.size.height-100);
    self.pageControl.currentPage = 0;
    self.pageControl.numberOfPages = [ArrayImages[_id_item] count];
    }


- (void)scrollViewDidScroll:(UIScrollView *)sender {
    if (!pageControlBeingUsed) {
        // Switch the indicator when more than 50% of the previous/next page is visible
        CGFloat pageWidth = self.scrollView.frame.size.width;
        int page = floor((self.scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
        self.pageControl.currentPage = page;
    }
}

屏幕

4

1 回答 1

0

这是食谱:

create a horizontal scroll view
set its content view and other properties U like
for each image
    create vertical scroll
    set its content view and other properties U like
    put image inside vertical scroll
    put other content in vertical scroll
    put vertical scroll in horizontal scroll
put horizontal scroll in main view

就是这样……

于 2013-11-08T15:11:37.520 回答