UIscrollview resize problem
i have a srollview with textfields and labels as its subview, for two textfields i want to show UIpickerview. For example: when user touches textfield11 i want to show a picker that slides up from the bottom of the screen, at this point i want to change height of my scrollview too, but it is not working.
CGRect scrollframe = scrollView.frame;
NSLog(@"scrollframe.height=%f, pick height=%f",scrollframe.size.height, pick.frame.size.height);
scrollframe.size.height -= pick.frame.size.height;
[UIView beginAnimations:@"start" context:NULL];
[UIView setAnimationDuration:0.2];
[UIView setAnimationBeginsFromCurrentState:YES];
[scrollView setFrame:scrollframe];
NSLog(@"开发者_运维知识库scroll height = %f",scrollframe.size.height);
NSLog(@"scrollview height = %f", scrollView.frame.size.height);
[pick setFrame:CGRectOffset([pick frame], 0, -220)];
[UIView commitAnimations];
This is console log..
2011-06-08 10:43:31.316 AESDirect[281:207] scrollframe.height=416.000000, pick height=216.000000 2011-06-08 10:43:31.316 AESDirect[281:207] scroll height = 200.000000 2011-06-08 10:43:31.317 AESDirect[281:207] scrollview height = 200.000000
This might help you:
[scrollframe setContentOffset:CGPointMake(scrollframe.contentOffset.x, scrollframe.contentOffset.y-100)];
You can call the above code via the same function from where you are calling the pickerView. So this way you don't have to change the height of the scrollview.
Your code should be like this then:
UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
[contentView setBackgroundColor:[UIColor clearColor]];
self.view = contentView;
UIScrollView *horizontalScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
[horizontalScroll setBackgroundColor:[UIColor blackColor]];
[horizontalScroll setDelegate:self];
[contentView addSubview:horizontalScroll];
UIPickerView *tempPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 220, 320, 100)];
[tempPicker setHidden:YES];
[contentView addSubview:tempPicker];
Make all three of them as Global in .h file and then you will have better control on their behavior. Your picker view is moving along with other items of scroll view because you might have add picker view as subview on your scroll view.
You have to change your contentsize and content offset and pickerview in view not in scroll view because if you add it in scroll view you will not be able to select values from picker view.
精彩评论