Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIScrollView内容偏移和设置内容大小?_Ios_Uiscrollview_Contentsize_Contentoffset - Fatal编程技术网

Ios UIScrollView内容偏移和设置内容大小?

Ios UIScrollView内容偏移和设置内容大小?,ios,uiscrollview,contentsize,contentoffset,Ios,Uiscrollview,Contentsize,Contentoffset,我有一个滚动视图,其中包含许多ui视图UIView对象被动态地添加/删除到scrollview中,其contentSize也被更改 我的问题是,如果setContentSize更改,其contentOffset会自动更改,并且当我从滚动视图中删除某个内容时,它不会停留在被删除的位置 如何控制和发挥作用 如果您要求,我会添加代码 当我删除某些内容时,将使用此方法: - (void) removeNameFromTheList:(id)sender{ //[doctorList setScroll

我有一个滚动视图,其中包含许多
ui视图
UIView
对象被动态地添加/删除到
scrollview
中,其
contentSize
也被更改

我的问题是,如果
setContentSize
更改,其
contentOffset
会自动更改,并且当我从
滚动视图中删除某个内容时,它不会停留在被删除的位置

如何控制和发挥作用

如果您要求,我会添加代码

当我删除某些内容时,将使用此方法:

- (void) removeNameFromTheList:(id)sender{

//[doctorList setScrollEnabled:NO];


UIButton *x = sender;

            for(UIView *subview in [x.superview.superview subviews])
            {
                if([subview isKindOfClass:[UILabel class]])
                {
                    [self redrawTheList:sender:((UILabel*)subview).text];

                    NSMutableArray * tempo = [[NSMutableArray alloc]init];

                    tempo = addedList;

                    for(int i=0; i<tempo.count;i++)
                    {
                        if([(NSString*)[tempo objectAtIndex:i] isEqualToString:((UILabel*)subview).text])
                        {
                            [addedList removeObjectAtIndex:i];
                        }

                    }



                    NSArray *cells = [tableView visibleCells];

                    for (DoctorListCell *cell in cells)
                    {
                        UILabel *tempLabel = (UILabel*)subview;


                        if([cell.doctorName.text isEqualToString:tempLabel.text])
                        {                    
                            [cell.plusButton setHidden:NO];

                        }



                    }


                }
            }

            [x.superview.superview removeFromSuperview];


  NSLog(@"000:%f",doctorList.contentOffset.y);

  float temp = doctorList.contentOffset.y;



  [doctorList setContentSize:CGSizeMake(10, 41+(counterRow*41))];


  float temp2 = doctorList.contentOffset.y;


  [doctorList setContentOffset:CGPointMake(doctorList.contentOffset.x, doctorList.contentOffset.y+(temp2-temp))];


  NSLog(@"111: %f",doctorList.contentOffset.y);
-(UIView*)createDoctorBox : (NSString*)name {


[addedList addObject:name];

NSString *myString = name;

CGSize stringSize = [myString sizeWithFont:[UIFont fontWithName:@"Helvetica-Bold" size:13]];


UIView *doktorKutu = [[UIView alloc]init];

[doctorList addSubview:doktorKutu];

UIView *doktorKutuBas = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 18, 36)];

[doktorKutuBas setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"doktor_isim_kutu_bas"]]];

[doktorKutu addSubview:doktorKutuBas];

UILabel * doktorKutuGovde = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, stringSize.width+3, 36)];

[doktorKutuGovde setFont:[UIFont fontWithName:@"Helvetica-Bold" size:12]];

[doktorKutuGovde setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"doktor_isim_kutu_1px"]]];

[doktorKutuGovde setUserInteractionEnabled:YES];


[doktorKutuGovde setText:myString];

[doktorKutu addSubview:doktorKutuGovde];



UIView * doktorKutuKic = [[UIView alloc]initWithFrame:CGRectMake(stringSize.width+13, 0, 18, 36)];

[doktorKutuKic setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"doktor_isim_kutu_kic"]]];

[doktorKutu addSubview:doktorKutuKic];

UIImageView *cancelImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"cikar"]];

cancelImage.frame = CGRectMake(-5,9, 18, 18);

[doktorKutuKic addSubview:cancelImage];

UIButton *cancel = [[UIButton alloc]initWithFrame:CGRectMake(-5,0, 20, 36)];

//[cancel setBackgroundImage:[UIImage imageNamed:@"cikar"] forState:UIControlStateNormal];

[cancel setUserInteractionEnabled:YES];

[cancel addTarget:self action:@selector(removeNameFromTheList:) forControlEvents:UIControlEventTouchUpInside];

[doktorKutuKic addSubview:cancel];

UITapGestureRecognizer *singlePress =[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSinglePress:)];

[doktorKutuGovde addGestureRecognizer:singlePress];

[doktorKutu bringSubviewToFront:cancel];


[doctorCommented addObject:doktorKutu];

[doktorKutuKic bringSubviewToFront:cancel];

[doktorKutu bringSubviewToFront:cancel];

dictRowKey = [NSString stringWithFormat:@"row%d",counterRow];


NSMutableArray *row = [[NSMutableArray alloc]init];

doktorKutu.frame = CGRectMake(5, yAxis, stringSize.width+30, 36);


if([doctorAddition objectForKey:dictRowKey]!=nil)
{
    row = (NSMutableArray*)[doctorAddition objectForKey:dictRowKey];

    if(row.count>0)
    {
        int totalWidth = 5;

        for(int i=0;i<row.count;i++)
        {
                totalWidth = totalWidth + ((UIView*)[row objectAtIndex:i]).frame.size.width+5;
        }

        if(totalWidth+stringSize.width<520)
        {
            doktorKutu.frame = CGRectMake(totalWidth, yAxis, stringSize.width+30, 36);

            [row addObject:doktorKutu];

            [doctorAddition removeObjectForKey:dictRowKey];

            [doctorAddition setObject:row forKey:dictRowKey];
        }
        else
        {
            doktorKutu.frame = CGRectMake(5, yAxis+40, stringSize.width+30, 36);

            yAxis= yAxis + 40.0;
            counterRow++;
            dictRowKey = [NSString stringWithFormat:@"row%d",counterRow];

            row = [[NSMutableArray alloc]init];

            [row addObject:doktorKutu];

            [doctorAddition setObject:row forKey:dictRowKey];



        }

    }

}
else
{
    [row addObject:doktorKutu];

    [doctorAddition setObject:row forKey:dictRowKey];
}    

float temp = doctorList.contentOffset.y;



[doctorList setContentSize:CGSizeMake(10, 41+(counterRow*41))];


float temp2 = doctorList.contentOffset.y;


[doctorList setContentOffset:CGPointMake(doctorList.contentOffset.x, doctorList.contentOffset.y+(temp2-temp))];


if(counterRow>3)
{

    CGPoint bottomOffset = CGPointMake(0, doctorList.contentSize.height - doctorList.bounds.size.height);
    [doctorList setContentOffset:bottomOffset animated:YES];
}



return doktorKutu;

}
-(void)从列表中删除名称:(id)发件人{
//[可记录的医生列表:否];
UIButton*x=发送方;
对于(UIView*子视图在[x.superview.superview子视图]中)
{
if([subview iskindof类:[UILabel类]])
{
[自重绘列表:发件人:((UILabel*)子视图).text];
NSMutableArray*tempo=[[NSMutableArray alloc]init];
节奏=添加列表;
对于(int i=0;i0)
{
int totalWidth=5;

对于(int i=0;i我认为您可以使用scrollRectToVisible:animated:Methoda来控制scrollview的滚动,您可以通过编程滚动来解决此问题

@使用


确保您的contentsize大于ScrollView的大小仍然,我无法实现我的目标,scrollRectToVisible无法工作
[scrollView scrollRectToVisible:subview.frame animated:NO];