Transform making UIView disappear on iPhone 6 device - ios

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.

Related

Center a UIView inside a TableViewCell

I've been facing an weird issue which I have never experienced before (pretty new to iOS). I am trying to develop a blog reader app and I am using a UITableView inside my main View. Within the TableView I have added 1 prototype cell and modified it's height to be somewhat bigger.
In order to create a "floating", "shadow" or "card" effect within the TableViewVell I have added another View which will contain a cover image and a summary.
The problem I am facing is related to the layout that is displayed by the Preview Assistant for Storybords.
Even though for iPhone 8 (xCode 9.1) everything looks fine based on the constraints that I have put in place, for iPhone SE and 8 Plus things look weirdly different even though during the simulation things do not really look as described.
I have watched WWDC Videos, YouTube Videos, even some great tutorials but none seem to go beyond the basics and actually cover this issue that I am facing.
Here is a screenshot:
XCode Storyboards Preview
I made a simplified demo ofthe project which can be checked out on GitHub:
https://github.com/sebastiannitu/ConstraintIssues
I would very much appreciated if seomeone would calrify this issue for me once and for all. I am sure it's just me doing something silly but I cannot really waste any more time with this. I've already invested about 2 weeks in trying to figure this out!
Thank you very much for your replies in advance!
It's a mild bug in Xcode, but no big deal. Do this:
Change the device type in the canvas, e.g. to iPhone SE.
Switch away to your code, e.g. ViewController.
Switch back to the storyboard. Notice that the constraints have now fixed themselves in the canvas!
Show the Preview for that device type.
So it's mildly annoying, but it does work. Here's the preview for the iPhone SE:
Here's the preview for the iPhone X:
your constraints setup is fine . problem is with only assistant editor. if you run it in your simulator, View (orange View) will resize currectly.
Here is the screenshot for orange View, when running in iPhone 8s (left) and iPhone 5s.
i am not uploading project, but if you have problem then let me know.

Autolayout works fine on iOS 8, but doesn't behave well on iOS 6 and 7 (I'm using XCode 6.2)

I'm using autolayout to correctly lay out some views inside a UICollectionViewCell. It works fine with iOS 8, but when I try to run it on iOS 7 or iOS 6, the cells appearance varies widely everytime they are laid out (sometimes I see small changes in size and positions - one or two pixels - and sometimes big changes, resulting in some pretty messed up cells).
I swear I tried hard to find anyone with the same problem, but I couldn't. I didn't find any answer that could help me solve or even get close to understanding the problem either.
I would appreciate any inputs on how to solve or even debug this better.
MORE INFO
I'm using Interface Builder to create the view and set up the constraints. The cell's view has a total of 17 subviews, including UIViews and their subviews, and they do have a great number of constraints.
I update a UIColletionView (which includes a table of my custom cells) everytime I press a button.
What I find outrageous here is that when I run the app, everytime I press the button, the cells' subviews change their positions and sizes. I never change any constraint or frame programatically.
Also, the behavior is worst on iOS6. The frames chage a lot more and autolayout runs really slow (it take 3-10 seconds to update the collection view on iPod Touch 5th Generation, even if it has only one cell).
Worst of all, if I keep updating the UICollectionView, sometimes XCode will complain of constraints not being simultaneously satisfied. But most of the time it works just fine.
I'm also running into crashes in some devices when removing some of my autolayout-enabled views from superview. I found this is a strange behavior of Autolayout engine, which could get to some bad calculations due to float errors. I'm wondering maybe this two problems are related.
As I couldn't find any help in the entire web after searching for almost an entire day, I'm starting to think this must be a stupid error with a stupid solution. I do hope so.
Thanks in advance!
SCREENSHOTS
I'm adding some screenshots to help you visualize the problem. To get those screenshots, I run the app on iPod Touch 5th generation with iOS 6. The behavior is different on iPhone 4 with iOS 7 (it behaves much better, but I still get the elements moving around some pixels).
Everytime I press the "Update" button, I remove the view which contains the UICollectionView from its superview (the entire screen) and add it again. I do not destroy this view, it is created only once. I thought that could be the origin of the problem (some autolayout calculation buffer holding values from previous layout), but destroying it didn't solve the problem (altough it did make the displacements less frequent and disturbing, but at the cost of performance).
This is the expected behavior. This is the view I get when the app open:
Misplaced views. This is the result of pressing the "Update" button for the first time:
Result after pressing the button a second time:
Result after pressing the button a third time:
If I keep pressing the button, I get layouts alternating between screenshots 3 and 4 (or at least they look pretty like the same).
I'M GIVING UP AUTOLAYOUT AND HERE IS WHY
Well, I'm really giving up using auto layout. I've spent almost a week learning to do a lot of thing with it (specially laying out and animating views). I thought it is a wonderful and powerful feature and I learned to love it. But then I needed to support iOS6 and iOS7.
I found it only works great on iOS8 (with any device, old or not). I don't know if I'm doing something really stupid, because I can't find any threads on the internet talking about three killing problems I've been facing.
I'll list them here just in case somebody come across this thread sometime in the future with the same problem or with a solution. They are listed ordered by the priority I gave to them to why I'm giving up autolayout.
1) Performance
Autolayout runs really slow on iOS6 and a little slow on iOS7 (compared to iOS8 - remember I'm developing with XCode 6.2 and iOS8.2 SDK). The same hardware with iOS8 runs the same code just fine.
To get to this conclusion, I ran my app in two iPod Touch 5, one with iOS6 and the other with iOS8. The difference in performance was pretty clear. Loading or dismissing a simple view (11 subviews) in iOS6 could take more than 5 seconds (on iOS 8, never took more than 1). On iPhone 4 with iOS7, the same code performed much better than in iOS6, but slower than in iOS8.
I'm sure it is an autolayout related problem because, using the same code, I disabled autolayout (and size classes) for some specific XIBs and they runned stupendously fast on iOS6, while the other views kept being slow (if you are going to try this, remember to delete the old app, clean the project and build it again, or it will still use autolayout).
2) Random crashes on specific devices with iOS6 or 7 when dismissing a view controller or removing a view from its superview
The problem is clearly stated here. It seems I'm bumping into the float error problem, because I can see some e-08 numbers on the crash log.
This is a serious problem for autolayout adoption. It's a random, unpredictable - but reproducible - crash. The same layout constraint can work in various devices, with different iOS versions. But it can also crash in some of them. Example: I had a view that worked fine on iPhone 4 (iOS7) and that crashed when dismissed on iPad Air (same iOS). The solution? Change the constraint's items relation from
x.width = y.widht*0.8 + 0
to
y.width = x.widht*1.25 + 0
which is equivalent matematically, but avoided the crash.
I searched a lot if anybody had a way to know when this crash could happen or how to tackle it down forever, so I could make my views without having to worry about testing them on every device, with every iOS version, to make sure it wouldn't crash. I couldn't find a away to fix it.
This crash doesn't seem to happen in iOS8.
PS: I tried removing the constraints from all my subviews before removing the view from superview, but then the crash occurred when removing one constraint. I couldn't find any good reason to why it was crashing when removed.
3) The problem I describe in the first part of this question
It's a third priority problem because I could solve this designing the cells without autolayout. This would be a minor problem if the rest of the app do not use cells, which is the case.
But it is still a problem I cannot understand nor solve with autolayout. When I remove autolayout, the cells are displayed just fine. And they do work fine on iOS8 and I double checked if I was using some specific iOS8 feature and I'm not.
BOTTOM LINE
I'm giving up autolayout while I have to support both iOS6 and 7 or until I can find a way to fix at least the first two problems I listed above.
I've tasted the power of Autolayout and I really like it, but I can't develop worrying about unpredictable crashes hidden on some mysterious dismiss in a specific hardware with a specific iOS version. Nor can I accept the poor performance of iOS6 (sometime soon we should drop support to iOS6, though, so this will be a lost problem).

Interface cut jumps on load in simulator and iOS 8, but not on iOS 7 real device

I have a problem with my interface on iOS 8 GM(real 5s) and iOS 8 Simulator(iPhone 5, 5s, 6 and 6+).
When I'm testing the app and I load my custom player view controller, the interface make a jump when interface is shown. And when testing on real app, instead of jump MPVolumeView is appearing in a some kind of expanding animation.
However, the problem is not there when I'm testing it on iOS 7 iPhone(the real one).
Also I've found out that if I remove all the constraints from the view that is loaded the jump issue disappears.
May it be a bug in iOS 8 behavior? Or it is some new behavior that I'm getting wrong?
EDIT: Testing on iOS 7 simulator definitely makes it look like it's some new behavior of iOS 8(on iOS 7 it works fine).
Here is the video for better understanding of the problem:
(black bar is MPVolumeView)
http://www.youtube.com/watch?v=gfc3n2syqo4
Okay, I've figured it out.
For some reason, if you set constraint from the view to the bottom layout guide, the view will jump on load. Don't know if this is expected behavior, I think I will post bug report for this one.
TL;DR remove bottom layout guide constraint and use other constraints.

portrait layout wont scroll in landscape orientation

Im quite new to XCode and Interface Builder, so forgive me if the solution is obvious.
I have designed a nice portrait IPhone view in interface builder (XCode 5) and have set the constraints on each of the elements (labels, text views, switches, buttons etc) so that they are positioned correctly in either 3.5 or 4 inch portait mode in the simulator.
However, when I rotate the simulator to landscape it breaks the design with elements overlaying each other and other elements disappearing (being clipped from the view) - and I expected this.
My idea of a solution is to put all of the UI elements inside a UIScrollView and set constraints on the scroll view so that it fills the screen in either portait of landscape mode.
After doing this, the portrait view is as before in the simulator, but in landscape view nothing scrolls, and none of my UI elements respect their constraints (stretch horizontally etc). Im still losing UI at the bottom and I cant scroll it into view.
I assumed that putting everything into the scroll view would simply 'fix' this issue, but the scroll view seems to do absolutely nothing at all. I have fiddled with various settings in interface builder but nothing fixes this.
There seem to be lots of long-winded solutions to this type of scenario based on code, but surely something this simple and common should just 'work'
What am I missing, or what have I done wrong, or does simple scrolling really have to be extensively coded in order to work ???
Putting all of your elements inside a scroll view won't really solve anything. Those elements would still need constraints to know how to position themselves in the scroll view. You need to be careful as well, as this solution sounds like something that goes against apples human interface guidelines. I'd advise against ignoring those, as Apple are known to reject apps that do this.
I'd say your problem is your constraints simply aren't setup correctly if elements are cover other elements and moving into the wrong places when rotated.
Annoyingly the WWDC videos section of the developer site is still down, but when it's back up, have a watch of the video of autolayout in Xcode 5, it will help explain what's going on.
If you want elements to completely change position when rotated however, you're likely to need more than just constraints, and would need to throw in some code to handle the transition between portrait and landscape. So it really depends on what the view is supposed to do when you rotate the device
OK, Ive figured it out. It IS a bug in either XCode 5 or IOS 7
I created 2 simple iphone UI's in interface builder - one in Xcode 4.6.3 targeting IOS 6.1 and the other in XCode 5 Beta 4 targeting IOS 7 beta 4.
The first app ran entirely as I had assumed, with the scroll view scrolling in landscape mode. The second app had no scrolling at all in the scroll view - so obviously a bug.

Accelerometer data reversed in iphone 5?

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.

Resources