即使在ios中滚动后,也可以在底部设置UIPickerView的位置

时间:2014-04-29 05:58:36

标签: ios uiscrollview uipickerview

我想点击UIPickerView时显示UITextField。我使用一种简单的方法来显示picker,如下所示:

-(void) showPickerView {

    [self.view resignFirstResponder];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.50];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

    CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;
    if(iOSDeviceScreenSize.height == 480){

        CGRect frame = self.picker.frame;
        frame.origin.y = 270;
        self.picker.frame = frame;
        frame = self.toolBar.frame;
        frame.origin.y = 226.0;
        self.toolBar.frame = frame;

    } else if(iOSDeviceScreenSize.height == 568){

        CGRect frame = self.picker.frame;
        frame.origin.y = 239.0;
        self.picker.frame = frame;
        frame = self.toolBar.frame;
        frame.origin.y = 195.0;
        self.toolBar.frame = frame;

    }

    [UIView commitAnimations];

}

如果我没有向下滚动,它会很有效。但是当我向下滚动时,我的picker被放置在showPickerView方法中提到的固定位置。现在我如何管理我的picker每次出现在底部。

2 个答案:

答案 0 :(得分:2)

解决方案1:

将您的选择视图添加到您的窗口。

解决方案2:

实现scrollview委托并连续调整帧。

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{


    CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;
    if(iOSDeviceScreenSize.height == 480){

        CGRect frame = self.picker.frame;
        frame.origin.y = 270;
        self.picker.frame = frame;
        frame = self.toolBar.frame;
        frame.origin.y = 226.0;
        self.toolBar.frame = frame;

    } else if(iOSDeviceScreenSize.height == 568){

        CGRect frame = self.picker.frame;
        frame.origin.y = 239.0;
        self.picker.frame = frame;
        frame = self.toolBar.frame;
        frame.origin.y = 195.0;
        self.toolBar.frame = frame;

    }



}

答案 1 :(得分:1)

我可以假设您在滚动视图中显示您的选择器,对吧? 如果是这样,那么您的选择器框架相对于UIScrollView而不是屏幕视图。 所以你必须考虑你的滚动视图偏移。这样的事情:

    CGRect frame = self.picker.frame;
    frame.origin.y = self.scrollvew.contentOffset.y + 270;

否则,您可以在UIScrollView之外显示您的选择器(只需将其添加到屏幕视图)。

相关问题