UIPopoverController and Keyboard on iOS 7 results on strange animation - ios7

On iOS 7, when you present a UIPopoverController, the system adds a UIView with some alpha effect to focus the user on the UIPopoverController. So far, so good.
The problem is that if you have a UIPopoverController that's being displayed from the bottom of your screen, and that UIPopoverController content has a UITextField (or anything else that brings the keyboard), the dimmed UIView animation doesn't follow the keyboard very well.
I've created a sample project to isolate the problem. Download Project
And a video of the same issue running on the simulator: Watch Movie
One solution could be to just disable the dimmed UIView as mentioned here, but I would like to keep it if possible.
Is there a workaround or maybe I'm doing something wrong?
I'm starting to consider to fill a bug for this.
Thanks.

Have you tried wrapping your code in a block to disable CoreAnimations implicit animation blocks? Something like this
[CATransaction begin];
[CATransaction setDisableActions: YES];
// Show your popover:
// [myPopover presentPopover:...]
[CATransaction commit];

Related

QLPreviewController delegate method doesn't get called in iOS 10, but does get called if ran earlier than iOS 10

Here is my code. This may sound like redundant question but my scenario is different as I am not adding QLPreviewController as a subview but present as a controller.
After downloading from dropbox, I present it like-
self.pdfViewController = [[QLPreviewController alloc] init];
self.pdfViewController.delegate = self;
self.pdfViewController.dataSource = self;
[self presentViewController:self.pdfViewController animated:YES completion:nil];
and I also have QLPreviewControllerDataSource, QLPreviewControllerDelegate listed as the protocol. Besides, it is working if being run in earlier than iOS 10.0.
Please help me.
It looks like iOS 10 has changed the way that QLPreviewController is presented. On iOS 9 when I preview an image by presenting the QLPreviewController modally I see a nice zoom effect and the initial state of the preview is with a black background and the navigation and toolbar hidden. I can tap the image to make the bars visible (which changes the background to white). Tapping again toggles the state.
On iOS 10 the same code results in the white background view appearing and the zoom animation being incorrect (it seems to appear from off the bottom of the screen).
I found that implementing this practically undocumented new data source method for iOS 10 fixed the issue:
- (UIView* _Nullable)previewController:(QLPreviewController *)controller
transitionViewForPreviewItem:(id <QLPreviewItem>)item
{
return [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:MIDPhotoImageRowIndex_Image inSection:MIDPhotoSectionIndex_Image]];
}
The view I return is the same view that previewController:frameForPreviewItem:inSourceView: is using as the reference for the original content's frame (i.e. the image view in my table cell).
The documentation for this delegate method at the time of writing just says "No overview available".
Implementing that method did mean that the previewController:frameForPreviewItem:inSourceView: is now called on iOS 10. I just wish there was a way to default to the original black background without navigation bars.

UIButton iOS 7 following UIKeyboard animation

I would like to animate a UIButton which is at the bottom of my UIView when the keyboard becomes/resigns first responder. Before iOS 7 I made a simple animation that moves the button, but now the animation of the keyboard is non linear, it starts faster and ends more slowly. I've been told to do it with the new UIKit Dynamics but don't have any idea of how can I achieve my goal. Any suggestion?
Thanks in advance.
Listen to keyboard notifications. There you can obtain the following information and animate your button accordingly.
UIKeyboardAnimationCurveUserInfoKey The key for an NSNumber object containing a UIViewAnimationCurve constant that defines how the
keyboard will be animated onto or off the screen.
Available in iOS 3.0 and later.
Declared in UIWindow.h.
UIKeyboardAnimationDurationUserInfoKey The key for an NSNumber object containing a double that identifies the duration of the
animation in seconds.
Available in iOS 3.0 and later.
Declared in UIWindow.h.
More information here:
https://developer.apple.com/library/ios/documentation/uikit/reference/UIWindow_Class/UIWindowClassReference/UIWindowClassReference.html#//apple_ref/doc/constant_group/Keyboard_Notification_User_Info_Keys
possible duplicate, another possible duplicate
#Leo: I've tried using those values but they didn't work for me (and others I've seen), so I ended up with this:
[UIView animateWithDuration:0.5
delay:0
usingSpringWithDamping:500.0f
initialSpringVelocity:0.0f
options:UIViewAnimationOptionCurveLinear
animations:animBlock
completion:completionBlock];

changing view controller when the device orientation changes

Im making an ios app in xcode 4 and I need a way of changing what is displayed on the screen when the device orientation changes.
does anyone know how to do this?
thanks.
probably you need to check first how to detect if the device orientation changes
see here: how to detect orientation change
then on the example on the link, you should know ho to change the view which is displayed on the screen. You can do it by using methods such as addSubview, presentModalViewController, pushViewController(for NavigationController)
eg:
[self presentModalViewController:aView animated:YES];
[self addSubview:aView];
[self.navigationController pushViewController:aView animated:YES];

iOS: how to stop text animation in partial curl

I'm using a partial curl modal in my iOS application. Please see this video:
http://vimeo.com/38643030
During the partial curl transition, the text in the round rect buttons is moving too. How can I stop this?
Put [self.view layoutIfNeeded] in the -viewDidLoad implementation for the view controller that's being shown via the curl animation. This makes the buttons & their contents lay out once before the animation starts instead of trying to do its layout (and redo it as things change around it) during the animation.
Just to add to rickster's answer, I had a similar problem with a UITableViewController and it was necessary to add
[self.view layoutIfNeeded];
[self.tableView layoutIfNeeded];
in the -viewDidLoad. Neither of the above statements worked on their own.

Odd behavior when showing UIPopoverController

In my iPad app, I save the state (visible/not visible) of a popover. So, during the launch of the app I initialize the UIPopoverController and tell it to show itself by using presentPopoverFromBarButtonItem:permittedArrowDirections:animated:. For the first argument (UIBarButtonItem), I use self.navigationItem.rightBarButtonItem. However, the popover keeps showing up on the left side of the screen (and not underneath the targeted button).
After the app is launched, the behavior is as expected. Any suggestions how to solve this?
For your information, I initialize the rightBarButtonItem and assign it to the navigationItem in the viewDidLoad method and before asking the popover to present itself. I have tried to call the popover in viewWillAppear and viewDidLoad, but the effect is the same.
My best alternative is to use presentPopoverFromRect:inView:permittedArrowDirections:animated: instead and "guess" the position depending on the orientation of the device.
Update: when I rotate the iPad, the popover does jump to the correct position. It seems that the barButtonItem's position is only determined at the last minute and after I ask my popover to present itself.
In situations like these where timing appears to be important I found that the trick of postponing an action until the next iteration of the run loop helps. If developing for iOS 4.0+, this can be easily achieved with GDC:
// call from viewDidAppear:
dispatch_async(dispatch_get_main_queue(), ^{
// call presentPopoverFromBarButtonItem:permittedArrowDirections:animated: here
});