Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

Resizing UIView at Runtime / No Longer Receiving Scroll Events

At runtime, I have a UIView (ViewA) that contains a UIWebView and a UITextField. In its normal (non-typing) state, the UIView takes up about 1/3 of the screen. On entering the text field, I need to not only display the keyboard, but make the UIView fill the screen (covering another UIView (ViewB) containing another UIWebView.

OK -- so my code to change the view is

- (void)animateView:(float)deltaY
{
const float movementDuration = 0.3; // seconds

[UIView beginAnimations: @\"anim\" context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: movementDuration];
// moves the frame up
self.frame = CGRectOffset(self.frame, 0, deltaY);
// resizes it
self.frame = CGRectMake(self.frame.origin.x,self.frame.origin.y - 49,self.frame.size.width,self.frame.size.height + 49);

[UIView commitAnimations];
}

- (float)getKeyboardHeight:(NSNotification *)notification
{
float keyboardHeight;
CGRect keyboardFrame = [[[notification userInfo]
objectForKey:UIKeyboardFrameBeginUserInfoKey]
CGRectValue];
keyboardHeight = keyboardFrame.size.height;
return keyboardHeight; // Tab bar point size
}

- (void)keyboardWasShown:(NSNotification *)notification
{
// Get the size of the keyboard. Requires iOS 3.2 or higher
float keyboardHeight = [self getKeyboardHeight:notification];

[self animateView:-keyboardHeight];

}

That seems to do the right thing visually (ViewA expands to the right dimensions and the UIWebView in ViewA displays properly) but the UIWebView in ViewA no longer responds to any events (scrolling, etc). In fact, the UIWebView in ViewB, even though it's under ViewA, is getting the touch events.

Based on my searching, I'm pretty sure it's something I've done incorrectly with setting the frame in animateView:, but can't for the life of me figure out what it is.

Any guidance is appreciated.
Post edited by rbanker on

Replies

  • Duncan CDuncan C Posts: 8,033Tutorial Authors, Registered Users
    rbanker;428503 said:
    At runtime, I have a UIView (ViewA) that contains a UIWebView and a UITextField. In its normal (non-typing) state, the UIView takes up about 1/3 of the screen. On entering the text field, I need to not only display the keyboard, but make the UIView fill the screen (covering another UIView (ViewB) containing another UIWebView.

    OK -- so my code to change the view is

    - (void)animateView:(float)deltaY
    {
    const float movementDuration = 0.3; // seconds

    [UIView beginAnimations: @\"anim\" context: nil];
    [UIView setAnimationBeginsFromCurrentState: YES];
    [UIView setAnimationDuration: movementDuration];
    // moves the frame up
    self.frame = CGRectOffset(self.frame, 0, deltaY);
    // resizes it
    self.frame = CGRectMake(self.frame.origin.x,self.frame.origin.y - 49,self.frame.size.width,self.frame.size.height + 49);

    [UIView commitAnimations];
    }

    - (float)getKeyboardHeight:(NSNotification *)notification
    {
    float keyboardHeight;
    CGRect keyboardFrame = [[[notification userInfo]
    objectForKey:UIKeyboardFrameBeginUserInfoKey]
    CGRectValue];
    keyboardHeight = keyboardFrame.size.height;
    return keyboardHeight; // Tab bar point size
    }

    - (void)keyboardWasShown:(NSNotification *)notification
    {
    // Get the size of the keyboard. Requires iOS 3.2 or higher
    float keyboardHeight = [self getKeyboardHeight:notification];

    [self animateView:-keyboardHeight];

    }

    That seems to do the right thing visually (ViewA expands to the right dimensions and the UIWebView in ViewA displays properly) but the UIWebView in ViewA no longer responds to any events (scrolling, etc). In fact, the UIWebView in ViewB, even though it's under ViewA, is getting the touch events.

    Based on my searching, I'm pretty sure it's something I've done incorrectly with setting the frame in animateView:, but can't for the life of me figure out what it is.

    Any guidance is appreciated.
    In general, I would suggest shifting everything up rather than resizing your views. The keyboard shifts up from the bottom, and it makes visual sense if the view controller's content view shifts up too. It just looks like the keyboard is pushing everything up.

    As to your code, I'm not sure what's causing the problem. I do have a test to run though.

    Comment out all the animation code, and just change the view's frame directly. See if the web view scrolls correctly.

    By default, the system turns off user interaction while an animation is running. I'm wondering if your code is leaving an animation i place. By getting rid of the animation code we can test that hypothesis.
    Regards,

    Duncan C
    WareTo

    mug

    Animated GIF created with Face Dancer, available for free in the app store.
  • rbankerrbanker Posts: 3New Users
    Thanks for the fast response! I tried your suggestion of disabling the animation and just setting the frame directly, but the result was the same -- the UIWebView in ViewA doesn't get the touch events (ViewB is getting them). I wish I could just shift the UIView up without resizing it, but the UI/UX designers are requiring the full-screen view, and unfortunately the size of the UIView is a different size when the keyboard is hidden vs. when the keyboard is displayed (according the the requested design).

    I've seen some indications online that there are problems with resizing UIScrollViews (and by relation, UIWebViews) and events, but haven't seen any reasonable solutions.
  • rbankerrbanker Posts: 3New Users
    As a test, I tried your suggestion of not resizing the view and just allowing the keyboard to push it up, and strangely, the result is still the same -- after the keyboard appears, the UIWebView in ViewA still does not get the events. Now I'm really stumped...
Sign In or Register to comment.