Как работать через UIScrollView?

В одном из моих viewController у меня есть scrollView, UIView, который содержит и UIImageView, UITextView и т. Д. Для scrollview вот код, который я написал:

    overViewScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0,0,screenFrame.size.width,screenFrame.size.height)];
        [overViewScroll setCanCancelContentTouches:NO];
        overViewScroll.pagingEnabled = YES;
        overViewScroll.clipsToBounds = NO;
        overViewScroll.indicatorStyle = UIScrollViewIndicatorStyleWhite;
        [overViewScroll setContentSize:CGSizeMake(screenFrame.size.width, screenFrame.size.height-25)];
        [overViewScroll setScrollEnabled:YES];
        [overViewScroll setAlwaysBounceVertical:YES];
        [overViewScroll setShowsVerticalScrollIndicator:YES];

UIView * completeView = [[UIView alloc]initWithFrame:CGRectMake(0,0,screenFrame.size.width,screenFrame.size.height)];
    UILabel* heading1 = [[UILabel alloc]initWithFrame:CGRectMake(5,0,310,30)];
    heading1.text = name;
    heading1.backgroundColor = [UIColor clearColor];
    UIFont * headingFont = [UIFont fontWithName:@"HelVetica" size:15];
    heading1.font = headingFont;
    [completeView addSubview:heading1];
    //NSSet * imageString = [projectHeroData valueForKey:@"imageURL"];
    NSString * urlString = @"";
    NSURL * url = [NSURL URLWithString:urlString];
    NSData * imageData = [NSData dataWithContentsOfURL:url];
    UIImage * projImage = [[UIImage alloc]initWithData:imageData];  
    UIImageView * imgView = [[UIImageView alloc]initWithFrame:CGRectMake(screenFrame.size.width/70,screenFrame.size.height/50,screenFrame.size.width-((screenFrame.size.width/70)*2),screenFrame.size.height/3)];
    imgView.image = projImage;
    imgView.backgroundColor = [UIColor blueColor];
    [completeView addSubview:imgView];

    UILabel * abstract = [[UILabel alloc]initWithFrame:CGRectMake(screenFrame.size.width/41,screenFrame.size.height/31 + screenFrame.size.height/3,screenFrame.size.width/4,screenFrame.size.height/30)];
    abstract.text = @"Abstract-";
    abstract.font = [UIFont boldSystemFontOfSize:fontSize];
    abstract.backgroundColor = [UIColor clearColor];
    [completeView addSubview:abstract];

    UILabel * lastUpdated = [[UILabel alloc]initWithFrame:CGRectMake(screenFrame.size.width/41 + screenFrame.size.width/5,screenFrame.size.height/31 + screenFrame.size.height/3,screenFrame.size.width-screenFrame.size.width/4,screenFrame.size.height/30)];
    NSString * string = modDate ;
    NSString * updated = [NSString stringWithFormat:@"Last Updated-%@",string];
    lastUpdated.text = updated;
    lastUpdated.backgroundColor = [UIColor clearColor];
    lastUpdated.font = [UIFont boldSystemFontOfSize:fontSize];
    [completeView addSubview:lastUpdated];

    UITextView * textView2 = [[UITextView alloc]initWithFrame:CGRectMake(screenFrame.size.width/70,(screenFrame.size.height/31 + screenFrame.size.height/3)+screenFrame.size.height/30,screenFrame.size.width-screenFrame.size.width/70*2,screenFrame.size.height)];
    textView2.text = abst;
    textView2.editable = NO;
    textView2.font = [UIFont systemFontOfSize:fontSize];
    textView2.backgroundColor = [UIColor clearColor];
    [completeView addSubview:textView2];

    [overViewScroll addSubview:completeView];
    [self.view addSubview:overViewScroll];

все добавляется в UIView, а UIView добавляется в UIScrollView. Но проблема в том, что он ведет себя странно, изображение не прокручивается полностью, а текст в Textview прокручивается сам по себе. Пожалуйста помоги!!


person Ashutosh    schedule 20.07.2011    source источник
comment
изменить размер содержимого вашей прокрутки   -  person ajay    schedule 20.07.2011
comment
что мне делать, увеличивать или уменьшать ??   -  person Ashutosh    schedule 20.07.2011
comment
когда когда-либо вы хотите прокрутить, тогда размер содержимого scrollview должен быть больше, чем его subview. означает, что в вашем случае размер кадра uiview меньше, чем uiscrollview   -  person ajay    schedule 20.07.2011


Ответы (2)


измените размер содержимого вашего scrollview. ваш размер UIview и размер uiscrollview будут такими же, если размер содержимого UIScrollview больше, чем размер его подпредставления, тогда произойдет прокрутка, измените строку [overViewScroll setContentSize: CGSizeMake (screenFrame.size.width, screenFrame.size.height- 25)]; как это [overViewScroll setContentSize: CGSizeMake (screenFrame.size.width, (screenFrame.size.height-25) * 2)] ;. это позволит вам горизонтальную прокрутку И по умолчанию textview имеет свойство прокрутки само.

person ajay    schedule 20.07.2011
comment
Хорошо, поэтому, если я не хочу, чтобы textView имел горизонтальную прокрутку и не хочу, чтобы он прокручивался сам по себе, а просто прокручиваю все представление. Что я должен делать/ - person Ashutosh; 20.07.2011

 overViewScroll =[[UIScrollViewalloc]initWithFrame:CGRectMake(0,0,screenFrame.size.width,screenFrame.size.height)];
    [overViewScroll setCanCancelContentTouches:NO];
    overViewScroll.pagingEnabled = YES;
    overViewScroll.clipsToBounds = NO;
    overViewScroll.indicatorStyle = UIScrollViewIndicatorStyleWhite;
    [overViewScroll setContentSize:CGSizeMake(320,600)];
    [overViewScroll setScrollEnabled:YES];
    [overViewScroll setAlwaysBounceVertical:YES];
    [overViewScroll setShowsVerticalScrollIndicator:YES];

 UIView * completeView = [[UIView alloc]initWithFrame:CGRectMake(0,0,screenFrame.size.width,screenFrame.size.height)];
UILabel* heading1 = [[UILabel alloc]initWithFrame:CGRectMake(5,0,310,30)];
heading1.text = name;
heading1.backgroundColor = [UIColor clearColor];
UIFont * headingFont = [UIFont fontWithName:@"HelVetica" size:15];
heading1.font = headingFont;
[completeView addSubview:heading1];
//NSSet * imageString = [projectHeroData valueForKey:@"imageURL"];
NSString * urlString = @"";
NSURL * url = [NSURL URLWithString:urlString];
NSData * imageData = [NSData dataWithContentsOfURL:url];
UIImage * projImage = [[UIImage alloc]initWithData:imageData];  
UIImageView * imgView = [[UIImageView alloc]initWithFrame:CGRectMake(screenFrame.size.width/70,screenFrame.size.height/50,screenFrame.size.width-((screenFrame.size.width/70)*2),screenFrame.size.height/3)];
imgView.image = projImage;
imgView.backgroundColor = [UIColor blueColor];
[completeView addSubview:imgView];

UILabel * abstract = [[UILabel alloc]initWithFrame:CGRectMake(screenFrame.size.width/41,screenFrame.size.height/31 + screenFrame.size.height/3,screenFrame.size.width/4,screenFrame.size.height/30)];
abstract.text = @"Abstract-";
abstract.font = [UIFont boldSystemFontOfSize:fontSize];
abstract.backgroundColor = [UIColor clearColor];
[completeView addSubview:abstract];

UILabel * lastUpdated = [[UILabel alloc]initWithFrame:CGRectMake(screenFrame.size.width/41 + screenFrame.size.width/5,screenFrame.size.height/31 + screenFrame.size.height/3,screenFrame.size.width-screenFrame.size.width/4,screenFrame.size.height/30)];
NSString * string = modDate ;
NSString * updated = [NSString stringWithFormat:@"Last Updated-%@",string];
lastUpdated.text = updated;
lastUpdated.backgroundColor = [UIColor clearColor];
lastUpdated.font = [UIFont boldSystemFontOfSize:fontSize];
[completeView addSubview:lastUpdated];

UITextView * textView2 = [[UITextView alloc]initWithFrame:CGRectMake(screenFrame.size.width/70,(screenFrame.size.height/31 + screenFrame.size.height/3)+screenFrame.size.height/30,screenFrame.size.width-screenFrame.size.width/70*2,screenFrame.size.height)];
textView2.text = abst;
textView2.editable = NO;
textView2.font = [UIFont systemFontOfSize:fontSize];
textView2.backgroundColor = [UIColor clearColor];
[completeView addSubview:textView2];

[overViewScroll addSubview:completeView];
[self.view addSubview:overViewScroll];

попробуйте, это сработает. Другой способ - использовать конструктор интерфейса и выбрать режим прокрутки и перетащить другой вид изображения метки в режиме прокрутки.

person ram    schedule 20.07.2011