Accelerometer data reversed in iphone 5? - ios

I'm creating a cocos2d game on iOS that uses the accelerometer. I just started testing on an iphone 5 and for some reason, it's reversing the accelerometer data - basically it behaves as if the screen orientation is 180 degrees flipped from how it actually is, tilting down causes it to send things up, left goes right etc.
It works fine on my iphone 4 running iOS 5 and on both my ipad running iOS 5 and my ipad running iOS 6. Not sure if it's an issue with just the iphone 5 or all iphones running iOS 6.
I can't find any mention of this issue online, wondering if anyone else is running into this and if you know of a solution.

OK I figured out what was going on. In iOS 6 the willRotateToInterfaceOrientation method is deprecated and no longer gets called. I had code in there to do two things - detect which landscape orientation the phone was loading into and adjust the variables accordingly, and to prevent the phone from flipping the orientation during gameplay (it's a tilt-to-move game). The reason everything was behaving as if the view was upside-down was because it was, and the phone's orientation was locked, and my code to correct for that wasn't being called. Here's what Apple says about willRotateToInterfaceOrientation:
The willRotateToInterfaceOrientation:duration:,
willAnimateRotationToInterfaceOrientation:duration:, and
didRotateFromInterfaceOrientation: methods are no longer called on any
view controller that makes a full screen presentation over itself—for
example, by calling presentViewController:animated:completion:. You
should make sure that your apps are not using these methods to manage
the layout of any subviews. Instead, they should use the view
controller’s viewWillLayoutSubviews method and adjust the layout using
the view’s bounds rectangle.
Now I just need to figure out how to use the willLayoutSubviews method to replicate my original functionality.

Related

Has anyone been able to override/block the new iPadOS 15 behavior of rotating iPhone apps in landscape?

The new behavior
Ideally we'd have native iPad support, but that's a ways off and not feasible at the moment. So for now we have to work with iPad running the iPhone app. Hybrid Swift and Objective-C using UIKit, for context.
The app I'm working on has a camera view controller that, prior to iPadOS 15, would not rotate the field of view between portrait and landscape. However, with this new rotation behavior, the UI is shown in portrait when the iPad is in landscape. In the case of the camera, the field of view is now flipped 90º. The captured images are not flipped, but the sideways field of view isn't a good look.
What I've tried/observed so far is the following:
This new rotation behavior is not governed by the UIViewController's rotation methods. Overriding shouldAutorotate and supportedInterfaceOrientations does not prevent this rotation. So this is happening at the device level, and not the view controller level.
At the device level, I only know of one way to programmatically change orientation, using the private setter on UIDevice's orientation property. Obviously, private APIs are a no-no for the App Store, and a hack to leverage them may break in the future. Not a good solution either.
At this point I'm at the end of my rope. I have scoured Google and StackOverflow to learn more about how this new feature works, at a technical level, but details are sparse. If anyone has more information or experience with this, that would be great. Even if the answer is 'no dice'. Thanks!

Transform making UIView disappear on iPhone 6 device

I have the weirdest problem specific to a iPhone 6 device. It's related to doing transform on a UIView.
If I do something like this on my UIView:
view.transform = CGAffineTransformMakeRotation(3.14/10)
Then the view disappears entirely. On my iPhone 5, then the view rotates as it should, but on the iPhone 6 it disappears entirely.
Any animation using transform also works perfectly on my iPhone 5 but on my iPhone 6 it doesn't show and sometimes shows "sharded" views of what I'm trying to animate.
This is iPhone 6 specific and only occurs on the device and NOT in the simulator.
Any suggestions on what this could be about?
It seems likely that something is using the frame of the view, which is undefined when you have a non-identify transform. For example, there might be a layoutSubviews method or constraint which is interacting badly with your view (It's better in iOS 8, but perhaps you ran into a yet-unsolved case). It's hard to tell what exactly is going on since you didn't supply a completely example.
You might try a tool like Xcode's view inspector or Reveal which can show you where your view is ending up and what constraints are acting on it. If that's not instructive, you should make a minimal example and post it.
It could also be differences in iOS version. Do your devices and simulators share the same point release?
It ended up being RubyMotion specific, so sorry for posting it with iOS tags - http://community.rubymotion.com/t/transform-making-uiview-disappear-on-iphone-6-device/344/4.

[UIScreen mainScreen].bounds Different iOS 8?

I just started testing my app on an iPad 2 thats still running iOS 7, because thats what I had lying around. As soon as I open up the app, the main view under the UINavigationController is offset and too small. Heres a picture of what I'm talking about:
The whole screen should be the light color. I use [UIScreen mainScreen].bounds to make the lighter view. I'm compiling this on the iOS 8.2 SDK. After logging the width and height, it seems like they're inverted. Is that how iOS 7 handles things? I think just checking if its running iOS 7 and swapping them will work, but I want to make sure this is the problem. Thanks.
EDIT:
Swapping them worked, but when I go to another view, that view is also rotated, and those are normal views.
iOS8 bounds are relative to orientation thus a device in landscape will have different bounds from the same one on portrait , in iOS7 this does not happen, the bounds are the same no matter if you are in portrait or landscape
See this answer

Ios app strange rotation behaviour after iOS 8 SDK update

I've been developing an iPad app which was working fine until i updated my Xcode to version 6 and my iPad to iOS 8.The problem i am encountering now is that when i change the orientation of my iPad i can catch the event but the views do not rotate accordingly.To be specific in my iPad with iOS 7 app rotates itself size of the views stay the same; for example if i start the app in portrait mode and change rotation to landscape there is a space on the right side of the uiview.In my iPad with IOS 8 views do not even rotate itself and stay the same all the time.I'm not using auto layout and app used to work like charm before IOS 8 SDK release.I need your help on finding articles and cause of the problems.Thanks in advance
probably the cause of problem is this line but i need to have this because otherwise my app won't release uiwebview from memory.
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
self.view.window.rootViewController=self;
}
Rotation handling has changed in iOS 8. Methods such as willRotateToInterfaceOrientation:duration: and didRotateToInterfaceOrientation: are now deprecated and replaced by viewWillTransitionToSize:withTransitionCoordinator:. Depending on how you're handling rotations in your app, you may have to make changes in your code to adapt to the new methods. Check chapter "Handling view rotation" in the UIViewController reference docs

CoreAnimation layer delegate + implicit animation differences in iPhone 4S / 4

I understand from a few posts on SO that in order for CoreAnimation-based implicit animations to work on iPhone, one has to set the delegate of the layer being animated to the view controller doing the animation. What tripped me up was this:
I started by testing on an iPhone 4S, where I forgot to do the set delegate step. The animations showed up fine.
I then tested on an iPhone 4, and couldn't for the life of me figure out why the animations weren't showing up. Of course, they worked once I added the set delegate step... but why?
Does anyone know why this is the case? Is it an issue of how the threads are being run on a 4S? I'm fairly new to CoreAnimation and the internal workings of iOS processes.
Edit for more info: both devices are on the same iOS version, 5.0.

Resources