开发者

How to update behind presentModalViewController when using UIModalTransitionStylePartialCurl?

开发者 https://www.devze.com 2023-03-31 17:02 出处:网络
How do I make a curled-up view update live as the user interacts with view being presented with presentMo开发者_StackOverflowdalViewController: under it?

How do I make a curled-up view update live as the user interacts with view being presented with presentMo开发者_StackOverflowdalViewController: under it?

The behaviour I want:

  1. User taps a view settings button.
  2. User taps controls in the view settings screen. Rather than dismissing view settings, the view automatically updates in the background.
  3. User taps something to dismiss view settings.

Imagine if in Maps tapping Map, Satellite, Hybrid didn't uncurl automatically but just updated the display.

I'm able to get notification that something's changed from the settings controller back to the main view controller. The main view controller can update and signal that it should redraw parts of itself, but actually updating the screen is intermittent. It will work 5 times in a row, then not work a couple times, then work another 5 times in a row. Dismissing the modal view always catches up the view underneath, however, so I assume the rendered image of my view is sometimes being cached or not being redrawn despite my request. But I can't think of a way to verify this.

This happens on both the device and the simulator.


While there might be multiple root causes of this behavior, here's a common issue I've seen that causes 'delayed' or 'intermittent' updates to UIKit views.

If the statements that update your presenting view (or the presented view) are running in a dispatch queue other than the main queue, UIKit may produce inconsistent results and timing in the actual UI update. You can usually tell by putting a breakpoint on the statements that update the UI and examining the name of the 'queue' displayed in Xcode's left-side debugger view. It should be 'com.apple.main-thread'. If it's not, that could be your issue. This can happen in quite a few delegate methods such as the network APIs.

Try wrapping your UI updates in: dispatch_async(dispatch_get_main_queue(), ^() { ... }); and see if that helps! You should only do this when needed and take care to use block-safe techniques as always.

I tested this in a brand new Universal app for iOS 7.0.3 using the iPad simulator with a view controller presented using the partial curl transition. I was able to replicate the original issue, including the intermittent update and the 'snap' update when dismissing the presented view by using a background queue in the code I provided above. Once I switched to the main queue, everything worked A-OK.

Let me know if this helps or if there was some other issue :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号