2014-04-07 73 views
0

我做了一个UIScrollView,我正在给它添加子视图。UIScrollView向上滚动到特定页面?

但是当我水平滚动它时,它会在scollview时传递一些对象。

我的代码是

#pragma mark - profileDataParsingFinish 
-(void)profileDataParsingFinish:(MainUserDAO *)mainUserDAO 
{ 

    NSLog(@"Profile Data Parsing Finish ... "); 

    currentDao=mainUserDAO; 

    [headerScroll setContentSize:CGSizeMake(3200.0f, 110.0)]; 
    NSString *newStr = [mainUserDAO.statusThumb substringWithRange:NSMakeRange(1, [mainUserDAO.statusThumb length]-1)]; 
    NSURL *imageURL=[[NSURL alloc] initWithString:[NSString stringWithFormat:@"%@%@",serverPart,newStr]]; 

    if([mainUserDAO.CityName isEqualToString:@"(null)"]){ 
    } 
    else 

    [livesTitle setText:mainUserDAO.CityName]; 
    [javaTitle setText:mainUserDAO.JobTitle]; 

    if([currentDao.maritialStatusPrivacyId isEqualToString:@"1"]){ 
     [maritialIcon setHidden:YES]; 
     [maritialLabel setHidden:YES]; 

    } 
    else if([currentDao.maritialStatusPrivacyId isEqualToString:@"2"]){ 
    /* 
     <MaritalStatus><MaritalStatusID>1</MaritalStatusID><Title>Single</Title></MaritalStatus><MaritalStatus><MaritalStatusID>2</MaritalStatusID><Title>Engaged</Title></MaritalStatus><MaritalStatus><MaritalStatusID>3</MaritalStatusID><Title>In a relation</Title></MaritalStatus><MaritalStatus><MaritalStatusID>4</MaritalStatusID><Title>Married</Title></MaritalStatus><MaritalStatus><MaritalStatusID>5</MaritalStatusID><Title>Divorced</Title></MaritalStatus><MaritalStatus><MaritalStatusID>6</MaritalStatusID><Title>Widowed</Title></MaritalStatus><MaritalStatus><MaritalStatusID>7</MaritalStatusID><Title>Not interested</Title></MaritalStatus></ArrayOfMaritalStatus> 
    */ 
     if([currentDao.maritialStatusId isEqualToString:@"1"]){ 
      [maritialLabel setText:@"Single"]; 
     } 
     else 
      if([currentDao.maritialStatusId isEqualToString:@"2"]){ 
       [maritialLabel setText:@"Engaged"]; 

      } 
      else 
       if([currentDao.maritialStatusId isEqualToString:@"3"]){ 
        [maritialLabel setText:@"In a relation"]; 
       } 
       else 
        if([currentDao.maritialStatusId isEqualToString:@"4"]){ 
          [maritialLabel setText:@"Married"]; 
        } 

        else 
         if([currentDao.maritialStatusId isEqualToString:@"5"]){ 
          [maritialLabel setText:@"Divorced"]; 

         } 
         else 
          if([currentDao.maritialStatusId isEqualToString:@"6"]){ 
            [maritialLabel setText:@"Widowed"]; 
          } 

          else 
           if([currentDao.maritialStatusId isEqualToString:@"7"]){ 
            [maritialLabel setText:@"Not Interested"]; 
           } 



    [maritialIcon setHidden:NO]; 
     [maritialLabel setHidden:NO]; 
     // [maritialLabel setText:currentDao.] 

    } 

    // NSData *data=[[NSData alloc]initWithContentsOfURL:imageURL]; 

    //[statusImage setImage:[UIImage imageWithData:data]]; 
    if(mainUserDAO.statusThumb==nil || [mainUserDAO.statusThumb isEqualToString:@""]){ 
    } 
    else{ 
     FavouritImageDownloader *downloder=[[FavouritImageDownloader alloc]init]; 
     [downloder startDownloading:mainUserDAO.statusThumb withButton:statusButton]; 


    } 



    if([mainUserDAO.statusMessage isEqualToString:@""] || mainUserDAO.statusMessage==NULL) 
     [statusLine setText:@"No Status Message Found"]; 
    else { 
     [statusLine setText:mainUserDAO.statusMessage]; 

    } 
    int imagex=650; 
    int imagey=28; 






    if([mainUserDAO.horoscopeThumb length]<=5 || mainUserDAO.horoscopeThumb==nil || [mainUserDAO.horoscopeThumb isEqualToString:@""] || [mainUserDAO.horoscopeThumb rangeOfString:@"no-image"].length > 0); 
    else 
    { 
     // imagex=imagex+90; 

     UILabel *favTite=[[UILabel alloc]initWithFrame:CGRectMake(imagex+5, imagey-20, 100.0f, 15.0f)]; 
     [favTite setTextColor:[UIColor blackColor]]; 
     [favTite setBackgroundColor:[UIColor clearColor]]; 
     [favTite setText:@"Horoscope"]; 
     [headerScroll addSubview:favTite]; 
     [favTite setFont:[UIFont boldSystemFontOfSize:12.0f]]; 


     //UIImageView *horoscopeThumb=[[UIImageView alloc]initWithFrame:CGRectMake(imagex, imagey,77.0f , 77.0f)]; 
     UIButton *horoscopeThumb=[UIButton buttonWithType:UIButtonTypeCustom]; 
     [horoscopeThumb setFrame:CGRectMake(imagex, imagey,77.0f , 77.0f)]; 
     [horoscopeThumb.imageView setContentMode:UIViewContentModeScaleAspectFit]; 
     horoscopeThumb.layer.borderWidth=0.8f; 
     horoscopeThumb.layer.borderColor=[[UIColor whiteColor]CGColor]; 

     if([currentDao.BirthPrvID isEqualToString:@"1"]) 
     { 
     } 

     else if([currentDao.BirthPrvID isEqualToString:@"2"]) 
     { 
      UILabel *ageLabel=[[UILabel alloc]initWithFrame:CGRectMake(55.0f, 55.0f, 20, 20)]; 
      if(currentDao.Birthdate!=NULL) 
      [ageLabel setText:[self findDateDifference:currentDao.Birthdate]]; 
      [ageLabel setTextColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"textcolor.png"]]]; 
      [ageLabel setBackgroundColor:[UIColor clearColor]]; 

      //[horoscopeThumb addSubview:ageLabel]; 
     } 


     [horoscopeThumb setImage:[UIImage imageNamed:@"Placeholder.png"] forState:UIControlStateNormal]; 
     horoscopeThumb.imageView.layer.borderWidth=0.8f; 
     horoscopeThumb.imageView.layer.borderColor=[[UIColor whiteColor] CGColor]; 
     [favTite setFont:[UIFont boldSystemFontOfSize:12.0f]]; 
     [headerScroll addSubview:horoscopeThumb]; 



     FavouritImageDownloader *favDownload=[[FavouritImageDownloader alloc]init]; 
     [favDownload startDownloading:currentDao.horoscopeThumb withButton:horoscopeThumb]; 
//  [horoscopeThumb addTarget:self action:@selector(showHoroscopeDetail) forControlEvents:UIControlEventTouchUpInside]; 

     [favDownload release]; 
    } 





    if([mainUserDAO.friendThumb length]<=5 || mainUserDAO.friendThumb==nil || [mainUserDAO.friendThumb isEqualToString:@""] || [mainUserDAO.friendThumb rangeOfString:@"no-image"].length > 0); 
    else { 
     imagex=imagex+112;//2 

     UILabel *favTite=[[UILabel alloc]initWithFrame:CGRectMake(imagex+10, imagey-20, 70.0f, 15.0f)]; 
     [favTite setTextColor:[UIColor blackColor]]; 
     [favTite setBackgroundColor:[UIColor clearColor]]; 
     [favTite setText:@"F.Friend"]; 
     [favTite setTextAlignment:UITextAlignmentCenter]; 
     [favTite setFont:[UIFont boldSystemFontOfSize:12.0f]]; 
     [headerScroll addSubview:favTite]; 



     UIButton *friendThumb=[UIButton buttonWithType:UIButtonTypeCustom]; 
     [friendThumb setFrame:CGRectMake(imagex, imagey,77.0f , 77.0f)]; 
     friendThumb.imageView.layer.borderWidth=0.8f; 
     friendThumb.imageView.layer.borderColor=[[UIColor whiteColor] CGColor]; 
     [headerScroll addSubview:friendThumb]; 


     favTite.center = friendThumb.center; 
     CGRect f = favTite.frame; 
     f.origin.y = imagey-20; // new y 
     favTite.frame = f; 



     FavouritImageDownloader *favdownloader=[[FavouritImageDownloader alloc]init]; 
     [favdownloader startDownloading:currentDao.friendThumb withButton:friendThumb]; 
     [friendThumb addTarget:self action:@selector(showFriendDetail) forControlEvents:UIControlEventTouchUpInside]; 
    } 

    ...............................// More Code here, I can't paste due to limit of Stack characters 

    [self.headerScroll scrollRectToVisible:CGRectMake(321, 
                 self.headerScroll.frame.origin.y, 
                 self.headerScroll.frame.size.width, 
                 self.headerScroll.frame.size.height) animated:YES]; 
} 

当我滚动,它省略了一些组件。

那么我怎样才能让它滚动到特定的位置,它必须滚动。

在此先感谢

回答

0

有两种滚动视图的方法,这将有助于您滚动到一个特定的点或框架。

[scrollview scrollRectToVisible:<#CGRect#>YOURRECT animated:YESORNO]; 

[scrollview setContentOffset:<#(CGPoint)#>YOURPOINT]; 

希望这会有所帮助。

+0

我需要把它们放到它滚动的位置。你能解释一下吗? –

+0

添加完所有视图之后,目前为止我的手中没有滚动条,除了在委托方法中处理它们之外,您有什么建议? –

+0

我想你正在寻找快照滚动,当你离开滚动它应该捕捉到一个视图,对不对? – iphonic

相关问题