の多くを保持するスクロールビューUIView
があります。オブジェクトは動的にUIView
追加/削除され、変更されます。scrollview
contentSize
私の問題は、setContentSize
変更contentOffset
すると自動的に変更され、何かを削除しscrollview
ても削除された場所にとどまらないことです。
どのようにコントロールして効果を得るのですか?
ご要望があればコードを追加します。
何かを削除すると、このメソッドが使用されます:
- (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;
}