UIScrollView向上滚动到特定页面?

时间:2014-04-07 09:52:45

标签: ios objective-c 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];
}

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

那么如何才能滚动到特定位置,它必须滚动。

提前致谢

1 个答案:

答案 0 :(得分:0)

有两种scrollview方法可以帮助您滚动到特定点或框架。

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

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

希望这有帮助。