Я изменяю размеры UIView и UIScrollView в зависимости от количества пикселей, которые перемещаются UITextViews.У меня все пиксели хранятся в int
переменных.В конце моего метода для заполнения всех этих текстовых представлений я использую это:
viewHeight += viewPixelsToBeAdded;
viewHeight -= viewPixelsToBeRemoved;
detailsView.frame = CGRectMake(0, 20, 320, viewHeight);
realDetailsView.frame = CGRectMake(0, 20, 320, viewHeight);
viewHeight - это постоянная высота представления, равная 1475. Я использую viewPixelsToBeAdded
и viewPixelsToBeRemoved
дляудерживайте общее количество пикселей, размеры которых необходимо изменить.Когда я использую приведенный выше код ... мой scrollView (detailsView) просто перестает прокручивать.В общей сложности.У меня есть свои объекты внутри зрения.Это представление внутри scrollView.Есть ли более простой способ изменить размер этого материала?Почему мой scrollView прекращает прокрутку, когда я увеличиваю или уменьшаю его высоту?Любая помощь будет принята с благодарностью.Я могу опубликовать весь метод populateLabels, если это будет необходимо.Я все равно чувствую, что с ним по длинному маршруту.
-(void) populateLabels {
NSString *noInfo = (@"No Information Available");
lblCgName.text = _Campground.campground;
NSString *cgLoc = _Campground.street1;
NSString *cgCity = _Campground.city;
NSString *cgState = _Campground.state1;
NSString *cgCountry = _Campground.country;
NSString *cgZipPostal = _Campground.zipPostal;
cgLoc = [[cgLoc stringByAppendingString:@", "] stringByAppendingString:cgCity];
cgLoc = [[cgLoc stringByAppendingString:@", "] stringByAppendingString:cgState];
cgLoc = [[cgLoc stringByAppendingString:@", "] stringByAppendingString:cgCountry];
cgLoc = [[cgLoc stringByAppendingString:@" "] stringByAppendingString:cgZipPostal];
lblCgLoc.text = cgLoc;
double dRate = [_Campground.regRate1 doubleValue];
double dRate2 = [_Campground.regRate2 doubleValue];
NSString *rate = [[NSString alloc] initWithFormat:@"$%0.2f",dRate];
NSString *rate2 = [[NSString alloc] initWithFormat:@"$%0.2f",dRate2];
if ([rate2 isEqualToString:@"$0.00"]) {
lblRate.text = rate;
} else {
rate = [[rate stringByAppendingString:@" - "] stringByAppendingString:rate2];
lblRate.text = rate;
}
double dPaRate = [_Campground.paRate1 doubleValue];
double dPaRate2 = [_Campground.paRate2 doubleValue];
NSString *paRate = [[NSString alloc] initWithFormat:@"$%0.2f",dPaRate];
NSString *paRate2 = [[NSString alloc] initWithFormat:@"$%0.2f",dPaRate2];
if ([paRate2 isEqualToString:@"$0.00"]) {
lblPaRate.text = paRate;
} else {
paRate = [[paRate stringByAppendingString:@" - "] stringByAppendingString:paRate2];
lblPaRate.text = paRate;
}
lblLocal1.text = _Campground.localPhone1;
lblLocal2.text = _Campground.localPhone2;
lblTollFree.text = _Campground.tollFree;
lblFax.text = _Campground.fax;
lblEmail.text = _Campground.email;
lblWebsite.text = _Campground.website;
NSString *gps = _Campground.latitude;
NSString *longitude = _Campground.longitude;
gps = [[gps stringByAppendingString:@", "] stringByAppendingString:longitude];
lblGps.text = gps;
int viewHeight = 1475;
int textViewDefaultHeight = 128;
int newTextViewHeight = 0;
int highlightsPixelsRemoved = 0;
int highlightsPixelsAdded = 0;
int notesPixelsRemoved = 0;
int notesPixelsAdded = 0;
int directionsPixelsRemoved = 0;
int directionsPixelsAdded = 0;
int rentalsPixelsRemoved = 0;
int rentalsPixelsAdded = 0;
int viewPixelsToBeRemoved = 0;
int viewPixelsToBeAdded = 0;
//----------------------------------------------------------------------------
txtHighlights.text = _Campground.highlights;
[self fitFrameToContent:txtHighlights];
newTextViewHeight = txtHighlights.contentSize.height;
if (newTextViewHeight > textViewDefaultHeight) {
highlightsPixelsAdded = newTextViewHeight - textViewDefaultHeight;
viewPixelsToBeAdded += highlightsPixelsAdded;
txtTentsHead.frame = CGRectOffset(txtTentsHead.frame, 0, highlightsPixelsAdded);
txtTents.frame = CGRectOffset(txtTents.frame, 0, highlightsPixelsAdded);
txtNotesHead.frame = CGRectOffset(txtNotesHead.frame, 0, highlightsPixelsAdded);
txtNotes.frame = CGRectOffset(txtNotes.frame, 0, highlightsPixelsAdded);
txtDirectionsHead.frame = CGRectOffset(txtDirectionsHead.frame, 0, highlightsPixelsAdded);
txtDirections.frame = CGRectOffset(txtDirections.frame, 0, highlightsPixelsAdded);
txtRentalsHead.frame = CGRectOffset(txtRentalsHead.frame, 0, highlightsPixelsAdded);
txtRentals.frame = CGRectOffset(txtRentals.frame, 0, highlightsPixelsAdded);
} else if (newTextViewHeight < textViewDefaultHeight) {
highlightsPixelsRemoved = textViewDefaultHeight - newTextViewHeight;
viewPixelsToBeRemoved += highlightsPixelsRemoved;
txtTentsHead.frame = CGRectOffset(txtTentsHead.frame, 0, -highlightsPixelsRemoved);
txtTents.frame = CGRectOffset(txtTents.frame, 0, -highlightsPixelsRemoved);
txtNotesHead.frame = CGRectOffset(txtNotesHead.frame, 0, -highlightsPixelsRemoved);
txtNotes.frame = CGRectOffset(txtNotes.frame, 0, -highlightsPixelsRemoved);
txtDirectionsHead.frame = CGRectOffset(txtDirectionsHead.frame, 0, -highlightsPixelsRemoved);
txtDirections.frame = CGRectOffset(txtDirections.frame, 0, -highlightsPixelsRemoved);
txtRentalsHead.frame = CGRectOffset(txtRentalsHead.frame, 0, -highlightsPixelsRemoved);
txtRentals.frame = CGRectOffset(txtRentals.frame, 0, -highlightsPixelsRemoved);
}
//----------------------------------------------------------------------------
txtTents.text = _Campground.tents;
//----------------------------------------------------------------------------
txtNotes.text = _Campground.notes;
[self fitFrameToContent:txtNotes];
newTextViewHeight = txtNotes.contentSize.height;
if (newTextViewHeight > textViewDefaultHeight) {
notesPixelsAdded = newTextViewHeight - textViewDefaultHeight;
viewPixelsToBeAdded += notesPixelsAdded;
txtDirectionsHead.frame = CGRectOffset(txtDirectionsHead.frame, 0, notesPixelsAdded);
txtDirections.frame = CGRectOffset(txtDirections.frame, 0, notesPixelsAdded);
txtRentalsHead.frame = CGRectOffset(txtRentalsHead.frame, 0, notesPixelsAdded);
txtRentals.frame = CGRectOffset(txtRentals.frame, 0, notesPixelsAdded);
} else if (newTextViewHeight < textViewDefaultHeight) {
notesPixelsRemoved = textViewDefaultHeight - newTextViewHeight;
viewPixelsToBeRemoved += notesPixelsRemoved;
txtDirectionsHead.frame = CGRectOffset(txtDirectionsHead.frame, 0, -notesPixelsRemoved);
txtDirections.frame = CGRectOffset(txtDirections.frame, 0, -notesPixelsRemoved);
txtRentalsHead.frame = CGRectOffset(txtRentalsHead.frame, 0, -notesPixelsRemoved);
txtRentals.frame = CGRectOffset(txtRentals.frame, 0, -notesPixelsRemoved);
}
//----------------------------------------------------------------------------
txtDirections.text = _Campground.directions;
[self fitFrameToContent:txtDirections];
newTextViewHeight = txtDirections.contentSize.height;
if (newTextViewHeight > textViewDefaultHeight) {
directionsPixelsAdded = newTextViewHeight - textViewDefaultHeight;
viewPixelsToBeAdded += directionsPixelsAdded;
txtRentalsHead.frame = CGRectOffset(txtRentalsHead.frame, 0, directionsPixelsAdded);
txtRentals.frame = CGRectOffset(txtRentals.frame, 0, directionsPixelsAdded);
} else if (newTextViewHeight < textViewDefaultHeight) {
directionsPixelsRemoved = textViewDefaultHeight - newTextViewHeight;
viewPixelsToBeRemoved += directionsPixelsRemoved;
txtRentalsHead.frame = CGRectOffset(txtRentalsHead.frame, 0, -directionsPixelsRemoved);
txtRentals.frame = CGRectOffset(txtRentals.frame, 0, -directionsPixelsRemoved);
}
//----------------------------------------------------------------------------
txtRentals.text = _Campground.rentals;
[self fitFrameToContent:txtRentals];
newTextViewHeight = txtRentals.contentSize.height;
if (newTextViewHeight > textViewDefaultHeight) {
rentalsPixelsAdded = newTextViewHeight - textViewDefaultHeight;
viewPixelsToBeAdded += rentalsPixelsAdded;
} else if (newTextViewHeight < textViewDefaultHeight) {
rentalsPixelsRemoved = textViewDefaultHeight - newTextViewHeight;
viewPixelsToBeRemoved += rentalsPixelsRemoved;
}
viewHeight += viewPixelsToBeAdded;
viewHeight -= viewPixelsToBeRemoved;
detailsView.frame = CGRectMake(0, 20, 320, viewHeight);
scrollView.frame = CGRectMake(0, 20, 320, viewHeight);
}