UIScrollView(在从按钮单击操作调用时)只会滚动到内容大小窗口底部的几个像素。仅在从某个函数调用时才会出现此问题。
- (void)adjustScrollView {
SVscrollableLayout.contentSize = CGSizeMake(SVscrollableLayout.frame.size.width, CGRectGetMaxY(bottomSubview.frame));
}
有问题的功能:
- (IBAction)BTNdeleteAction:(id)sender {
[self clearSubviews];
//Do some stuff to remove the deleted subview
[self displaySubviews];
[self adjustScrollView];
}
- (void)temporarilyClearClasses {
int numberOfClasses = [self loadNumberOfClasses];
for (int i=0; i<numberOfClasses; i++) {
UIButton* TXTclassDisplayTemp = (UIButton*)[self.view viewWithTag:100+i];
[TXTclassDisplayTemp removeFromSuperview];
UIButton* BTNdeleteButtonTemp = (UIButton*)[self.view viewWithTag:200+i];
[BTNdeleteButtonTemp removeFromSuperview];
}
}
- (void)printClasses {
int numberOfClasses = [self loadNumberOfClasses];
NSArray* classNames = [NSArray arrayWithArray:[self loadClassesArray]];
int yPlacement = 0;
if (numberOfClasses != 0) {
if (noClasses == YES)
for (int i=0; i<numberOfClasses; i++) {
UIButton* TXTnewClass = [[UIButton alloc] initWithFrame:CGRectMake(0, 10+(50*i), self.view.frame.size.width, 35)];
TXTnewClass.tag = 100+i;
[TXTnewClass addTarget:self
action:@selector(TXTclassDisplayAction:)
forControlEvents:UIControlEventTouchUpInside];
deleteAllButtonYplacement = CGRectGetMaxY(TXTnewClass.frame)+10 ;
UIButton* BTNdeleteClass = [UIButton buttonWithType:UIButtonTypeCustom];
BTNdeleteClass.frame = CGRectMake(10, yPlacement+10+(50*i), 70, 35);
BTNdeleteClass.tag = 200+i;
[BTNdeleteClass setTitle:@"Delete" forState:UIControlStateNormal];
if ([self editingStatus] == OFF)
BTNdeleteClass.hidden = YES;
[SVscrollableLayout addSubview:BTNdeleteClass];
if (CGRectGetMaxY(TXTnewClass.frame) <= SVscrollableLayout.frame.size.height) {
SVscrollableLayout.contentSize = SVscrollableLayout.frame.size;
}
else {
while (CGRectGetMaxY(TXTnewClass.frame) > SVscrollableLayout.contentSize.height) {
SVscrollableLayout.contentSize = CGSizeMake(SVscrollableLayout.frame.size.width, SVscrollableLayout.contentSize.height + 5);
}
}
}
}
else {
TXTnoClasses.hidden = NO;
BTNeditClassList.enabled = NO;
BTNeditClassList.alpha = 0.4;
}
float centerHorizontal = self.view.frame.size.width / 2;
float deleteAllButtonXplacement = centerHorizontal - (93/2) - 3;
NSLog(@"%f", BTNdeleteAll.frame.size.width);
[self refreshDeleteButton:CGRectMake(deleteAllButtonXplacement, deleteAllButtonYplacement, 93, 44)];
[self adjustScrollView];
}