Mobile Safari - Input caret does not scroll along with overflow-scrolling: touch

后端 未结 10 2311
攒了一身酷
攒了一身酷 2020-12-25 15:24

I know that Mobile Safari won\'t fire events while in \"momentum\" (-webkit-overflow-scrolling: touch;) scrolling. But this is not entirely the same thing, because Safari ha

10条回答
  •  没有蜡笔的小新
    2020-12-25 15:49

    This was a while ago and I think it was fixed on IOS11.x, of course we still need to support older versions, the suggestions above gave me a hint but none of them worked 4 my setup. I used onFocus to trigger a delayed function that adds/deletes a char to the current focused field. I'm using a flat angularJS/iOS hybrid.

    on my html side

    ... setting up my form
    

    on my JS side the relevant code is

    function pirouette_4_IOS()
    {
      try
      {
    
        document.activeElement.value += 'x';
        document.activeElement.value = document.activeElement.value.slice(0,-1);
      }
      catch(err)
      {
        alert(err.message);
      }
      finally
      {
        tweak4IOS = 0;
      }
    }  // --- end of pirouette_4_IOS---
    ...
    var tweak4IOS = 0; // init the flag
    

    Finally in the Obj-C I set the var in the keyboard pop

    - (void)keyboardDidShow:(NSNotification *)sender {
    CGRect frame = [sender.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    
    homeWeb.frame = CGRectMake(homeWeb.frame.origin.x, homeWeb.frame.origin.y,
                               homeWeb.frame.size.width , homeWeb.frame.size.height - frame.size.height     );
    
    self.pinBottom2.constant = frame.origin.y;
    
    // set the JS var so it is done only when keyboard pops initially
    [homeWeb stringByEvaluatingJavaScriptFromString:@"tweak4IOS=1;"];
    

提交回复
热议问题