Force rotation without user knowing - ios

My app allows a user to create an invoice. Data can be input in either landscape or portrait.
The user is then able to save the quote and view saved quotes in a collection view. Similar to Pages on iOS. The size of the tiles are the aspect ratio of the device in portrait view.
So if the user saves a quote I generate a screen shot of the view and save it so that it can be viewed in the tiled view (like iOS pages). This works all fine if the user saves when the device is in portrait. If they save while landscape it sucks.
So my question is, there a way I can rotate the view behind the scenes, generate a UIImage from it all without the user knowing noticing any orientation change.

If you are running the code that rotates it and takes a screenshot in the same thread then as long as you rotate it back before the thread finishes running, the device's screen will not update. Simply rotate everything (or if you have too many objects to rotate, take a screenshot of it all then rotate that screenshot) now take a screenshot of your new rotated view (or if you took a screenshot and rotated it don't do anything, you're done) then rotate everything back (again unless you just took a screenshot then rotated that)... If you need a screenshot method that can run in 1 thread use the CGContext code.
(To answer your question, rotating is always behind the scenes, it only becomes "in front" of the scenes when your thread ends... so if you rotate it back before the end of your thread the user will never see it because the device's screen will not update until after it has been rotated twice, there and back again.... bingo!)

Related

How can I detect if the Launch Storyboard happened?

does anyone know if there is a way to tell if the launch storyboard executed? Or is there a way to detect if the launch image was displayed?
Basically my app consists of just one view controller with some views (all created programmatically), plus the launch storyboard which I added to the project recently which seems to be working OK.
The reason why it would be useful for me to know if the launch storyboard happened is that my app is a game which basically consists of a big 2D scene that you can zoom into and pan around using the usual touch gestures. When the game starts for the first time it starts fully zoomed-out and centered on the scene: so that is what the launch image matches. But the player pans around and zooms-in on various things, so when they press the home button they could be zoomed into any part of the picture. So when they touch the app's icon to relaunch, if the launch storyboard happens it needs to put their pan/zoom position back to the initial centered zoomed-out position (otherwise as soon as the app gets going it would appear to the user to suddenly snap from the initial position represented in the launch image to where they were, not giving a smooth user experience).
What I do at the moment is -- if applicationDidEnterBackground: method gets called I assume that when the user relaunches the app, by touching the icon, that the launch storyboard will be executed. But the launch storyboard doesn't always happen after it hibernated via applicationDidEnterBackground:, especially if it is only a few minutes since the user pressed the home button.... and those times when the launch storyboard does not happen I need not inconvenience the player and put them back to the initial zoomed-out centered position, I could just let them carry on at the position they were.
I've not used storyboards before, but as I understand it launch storyboard are a special case where you can't make any connections to code because your app's not actually running yet, so I can't think of a way to set a variable, for example, to show the story board happened.
Anyone got any ideas?
Cheers,
Jon
Just use the viewDidLoad method provided by the UIViewController.
Just override the method in your ViewController and then you can perform the task you want when your View(Storyboard) is loaded.
Example:
#implementation MyViewController:UIViewController
-(void)viewDidLoad{
//Insert your code here
}
#end

Animation in Launch Screen in xcode 6

I want to animate a set of images in my Launch Screen, but I do not know how. I have seen some tutorials telling me to put code in the App Delegate (DidFinishLaunchingWithOptions) and nothing has worked.
Could someone help me animate my Launch Screen?
I am supposing that you do quite a bit of work on launch, and you do not want your user to stare at a static image while this work is going on. What you need to do is do the work in the background (using gcd). This way, the launch screen will be gone quickly. However, you are not ready of course: hence your need for animations. So what I do is add my own equivalent of the start screen on top of my first visible UIView, do my animations and then tear down my start up screen. If you want to see what I do in action, try it out with my App (The Opera Player)

camera view - can settings disrupt button response on a camera view on iPhone 5S?

I have a strange situation...
I implemented an in-app camera based on Apple's AVCam sample. It works just fine. My question is not about the actual camera implementation, but rather... What could cause a view's buttons to work on one iPhone 5S but fail on another iPhone 5S. Both are using the same build of the app, they have the same iOS version installed (7.0.4), etc.
The problem is...the camera starts and the camera preview displays just fine, but the buttons on that view (i.e. the shutter release, flash options, front/back camera switch, etc) all fail to respond. His iPhone 5S is the only one out of 4 iPhone 5S's that has the problem.
Trying to narrow down what can be different until I can hook the "sad" iPhone 5S up to my debugger in a few days when I see my client again (it's his)... we did notice that my phone asked for permission to access my photos and his did not...
Is there perhaps some system setting that he could have enabled that would cause this check to be skipped? I ask because I wonder if the camera scene's view controller is waiting for something from that check and therefor hanging the UI.
Any ideas would be appreciated
Finally tracked down the issue...
The difference was that on my developer phone, I had a few hundred to 1000 pictures in my camera roll. On my client's phone, he had about 6,000 pictures, so obviously getting those takes longer. If we were patient, the view eventually did come back alive after the enumeration block finished.
Also, I was asking my UICollectionView to scroll to the end (where the newest photos are) after it had finished loading all the camera roll images into itself. With few photos, the timing was fine, but with lots of photos, the timing was off and it was trying to scroll before it had finished enumerating. The solution, since there is no callback for "didFinishReloadingData" was no call the scroll method using -performSelector:withObject:withDelay to ensure that it gets called AFTER the enumeration block and reloadData are finished.

UIStatusBar + toggling full frame video + rotations = frame problems

My video (AVPlayer instance) plays in a smaller "minimized" window to start. Touch the screen to show the controls, and allow the user to expand it to full screen, which covers the status bar. I'm giving the viewController this for its full frame:
[[UIScreen mainScreen] bounds]
But the viewController still thinks the status bar is there, even if I hide it first:
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide]
So the video screen starts below the unseen status bar, at (0, statusBarHeight). If I rotate the device with the controls visible (which makes the status bar visible), the problem remains. If I rotate the device when controls are hidden (and the status bar is missing), everything corrects itself, and the video window starts at (0,0) as expected.
My solution has been to start the full screen video window at (0, -statusBarHeight), then watch for a rotation with no controls, when I can then put the video window back to origin. Yuck.
When I minimize the video back to the original size, if there has been a rotation with no controls, the video window will be too high by (statusBarHeight) pixels.
So another boolean to tell me, when I minimize the video, if I should correct it's "real" position by (0, +statusBarHeight). Double yuck.
If, at this point, we rotate the device, everything is good. But if we instead maximize the video right away, then the full screen video is too high by (statusBarHeight) pixels. Triple yuck!
Okay, more booleans, but this is all complicated by the fact that the video engine is a separate framework, and the 'controlling app' also has similar problems.. AAH!
Am I going about this in the wrong way? It's just getting all too complicated and fragile. I know (by looking at other apps out in the wild) that this is a common problem - I have a list of apps that exhibit the same behaviour. Is there a better way?
I wrote a very simple app to recreate this problem, and used up a "Technical Support Incident" to ask Apple's Developer Technical Support about it. They advised me to file a bug report (ID 12685127). They say:
AVPlayer is definitely not taking into account the status bar ..
and
I'm afraid I don't see a better solution, other than correcting for this as you are doing now ..

ipad sprite/atlas animation

I have an iPad app, where I need an animation full screen - running in a transparent UIView.
This animation is running every time the user is winning.
The question is, would you go for a sprite animation with a very large image as the source or would you go for a small video clip?
Remember that it has to be transparent - it is starts floating around.
Any input regarding directions is appreciated.
Thanks
I would use a sprite, loading a movie each time user wins is much more expensive than simply showing a sprite.
Besides, to show a video with transparent background you will have to iterato throught all player controller subviews and change backgroundColor like this

Resources