dogo / SCLAlertView

Beautiful animated Alert View. Written in Objective-C
MIT License
3.5k stars 534 forks source link

Is this an SCLAlertView bug, or an Apple bug? #296

Closed pnome closed 3 years ago

pnome commented 3 years ago

I'm having issues with the SCLAlertView dialog moving when the keyboard appears on the iPad

The only way I can get it to work correctly is if the SCLAlertDialog with the text field is called in the actionBlock of a previous SCLAlertDialog.

If it wasn't for that strange fact, I'd be certain this is an Apple bug.

I have a detailed video showing the issue here. The description of what's happening in the video follows https://www.loom.com/share/7b4c14d7024142ccba1d8b33839c2294

Here's what's happening: The alert dialog has a text field, and responds to the keyboard by animating itself further up the screen.

In the video I demonstrate how the exact same function to display the dialog results in different behaviour if called in different ways.

The method I'm calling is [self renamePreset], and that method simply shows the SCLAlertView dialog and sets the text field as first responder.

The three ways I'm calling it are:

  1. In the action block of a UIAlertController dialog button
  2. In the action block of an SCLAlertView dialog button
  3. Same as 2, but dispatched to the main queue after a 1 second delay

The SCLAlertView dialog that is being called has a text field, and when that becomes the first responder, the SCLAlertView responds to the keyboardWillAppear notification by animating itself up the screen with a displacement I've labelled yDisp.

In the console, you can see the print out of the frame.origin.y before the animation, and after the animation, along with the yDisp being applied.

Here's the issue...

If the y displacement is set to 320, all three methods of calling the dialog result in the same behaviour. That is, the dialog moves up the screen when the keyboard would appear (note, you don't see the keyboard because I'm in the simulator, but it's responding to the notification anyway)

However, if I change the y displacement by 100 pixels, I get different behaviour depending on how the method was called. If I called it with the UIAlertController (1. above), then you can see the dialog animates, but instead of moving up the screen, it quickly dips down, and then animates to the centre of the screen. The same thing happens if it's called from SCLAlertView button with a 1 second delay.

It only behaves correctly, if called in the action block of an SCLAlertView button.

I can't figure out why this would happen. The only thing I'm changing is the end location for my animation by modifying a single variable.

Any ideas how I might debug this, or is it an Apple thing?

Thanks for reading/watching/suggesting!

Joe

pnome commented 3 years ago

I posted another issue which shows this problem inside the example app. So, it's not related to my code.