Change zoomScale and contentOffset of UIScrollView in UIApplicationStateBackground state

▼魔方 西西 提交于 2019-12-05 09:14:44

问题


I know it's not recommended to change any view appearance when the application is moved to background state, but for my specific task I cannot postpone this activity and I really like to complete it in a couple of seconds after the user hits the home button.

That's what I do: I load a webpage in a UIWebView and after loading completion I change the contentOffset and zoomScale in order to make a specific screenshot of that webpage. When the app is in active application state everything works fine.

Now I wanted to add some more multitasking capabilities. I encapsulated the above described webpage loading and rendering activity in a protected background task (iOS Task Completion), in order to complete it even when the user hits the home button.

I have noticed that the page loading and the rendering of the webpage screenshot (with the renderInContext: method) works just fine in background, BUT it seems that the webview (i.e. the encapsulated UIScrollView instance) does not react on setContentOffset: and setZoomScale: messages as soon as the app is in background..

So I'm asking you if you know any alternatives to change the content offset / zoomscale? (modifications directly on CALayer?) Or any method to "force" the scrollview to perform the content changes even in background.

PS: On the iOS simulator everything works fine even in application background state, but on real devices it does not.

EDIT: I have created a simple demo project that demonstrates the issue. You can download it here (please read the instructions in the zip file): http://dl.dropbox.com/u/3556271/BackgroundBugDemo.zip

I appreciate every hint or tip. Thanks!

来源:https://stackoverflow.com/questions/15604276/change-zoomscale-and-contentoffset-of-uiscrollview-in-uiapplicationstatebackgrou

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!