iOS UIPickerView:如何限制滚动范围

时间:2015-06-20 11:11:17

标签: ios uipickerview

当您滚动UIPickerView时,您可以在触控板上上下移动手指 - 远远地向上和向下移动屏幕的大小。有没有办法限制这个滚动范围上下移动到UIPickerView的区域?那么,一旦您将手指移到UIPIckerView function SaveToDisk(fileURL, fileName) { //alert("yes i m working"); // for non-IE if (!window.ActiveXObject) { var save = document.createElement('a'); save.href = fileURL; save.target = '_blank'; save.download = fileName || 'unknown'; var evt = new MouseEvent('click', { 'view': window, 'bubbles': true, 'cancelable': false }); save.dispatchEvent(evt); (window.URL || window.webkitURL).revokeObjectURL(save.href); } // for IE < 11 else if ( !! window.ActiveXObject && document.execCommand) { var _window = window.open(fileURL, '_blank'); _window.document.close(); _window.document.execCommand('SaveAs', true, fileName || fileURL) _window.close(); } } 的滚动范围之外?我正在制作function downloadme(x,y){ myTempWindow = window.open(x,'','left=10000,screenX=10000'); myTempWindow.document.execCommand('SaveAs','null',y); myTempWindow.close(); } 作为游戏中的微调器,我需要实现这一目标才能实现公平游戏。

2 个答案:

答案 0 :(得分:1)

您可以将UITapGestureRecognizer与UIPickerView一起使用,然后您就可以获得坐标。如果你得到你想要的框架中的点,那么你的工作就会返回

答案 1 :(得分:0)

// viewDidLoad中

UILongPressGestureRecognizer* gestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(pickerLongPressDetected:)];
    gestureRecognizer.minimumPressDuration = .001;
    gestureRecognizer.cancelsTouchesInView = NO;
    gestureRecognizer.delegate = self;
    [self.rollerView addGestureRecognizer:gestureRecognizer];

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
    // return
    return true;
}

-(void)pickerLongPressDetected:(UILongPressGestureRecognizer *)gesture
{
    CGPoint touchPoint = [gesture locationInView:self.view];

    CGRect frame = self.rollerView.frame;

    if(!CGRectContainsPoint(frame, touchPoint))
    {
        //methods for when you scroll outside of your picker view's frame
    }
}