UITextView after CATransform3D: scrolling all out of whack - ios

So I have a UITextView, and in viewDidLoad I rotate its layer so it appears to be slanted back into the screen (sort of like the Star Wars opening crawl).
The problem is that scrolling is all messed up. Dragging up will scroll for a bit, then jump backward or similar; on the simulator it will even crash sometimes with an error about a coordinate containing NaN.
Similarly, when I try to automatically scroll the UITextView via [UIView animateWithDuration:...] I also get unexpected skips, jerks, etc.
I assume this has something to do with the fact that I've manipulated the layer, but the touch events as well as the animations are registered on the view... Or something like that?
Anyway, I'm pretty stumped.

Are you using constraints to position the text view? There seem to be issues with using transformations and constraints together. A common workaround seems to be to wrap the offending item in another view. The big issues are on iOS7, but some applies to iOS8 as well. This link discusses the issues which may be your issue:
How do I adjust the anchor point of a CALayer, when Auto Layout is being used?

Related

UICollectionView clipping on rotation, fixed as soon as you scroll

I’m using a UICollectionView to display three cells vertically, which each contain a UIView. It looks something like this:
If I rotate the device, it ends up looking like this:
I’m using AutoLayout to rotate the collection view, everything seems to be working properly, but when I rotate (this can be from portrait to landscape, or landscape to portrait), the collection view seems to clip its cells. If I turn on the view debugger at this point, it renders it perfectly there, like this:
As soon as I touch the collection view (i.e. scroll it slightly), the issue is fixed, and from then on it renders properly until I rotate again.
The issue occurs on both simulator and device, and when changing from any orientation to any other. It only clips until the collection view is touched, at which point it fixes itself.
I’ve tried lots of things already, replacing the YouTube views here with regular UIViews, manually calling scrollViewDidScroll: on the collection view after I rotate (and before), telling the collection view to reload its data, reload items, turning off clip or mask to bounds, invalidating the auto-resizing constraints, just about everything obvious that I can think of.
What’s puzzling me the most is the view debugger – everything there is perfect, it’s just when it renders out on-screen that it’s clipping. This issue occurs across the board, on all devices, phone and pad. There’s nothing in the view debugger hierarchy that looks like it’s overlapping them. Everything’s where it’s supposed to be, even if I break at the broken point and print frames, etc., it’s just clipping when it renders somehow.
Anyone have any suggestions?

Preventing unwanted animations in iOS

I am attempting to animate the height of my UITableView in a smooth manner. That's working fine, however there is a bizarre side effect I am having trouble eliminating and that is as new cells are shown in the table view while it is expanding, those cells are animating their "construction". For example, some of the labels appear to "slide in" from an edge of the cell.
This is completely undesired and looks horrible. This has been a recurring problem for me and I'd like to know what the proper solution is for dealing with this.
I've tried encapsulating various things in [UIView performWithoutAnimation:], but it's never obvious where or at what point I should be wrapping things in this, and it seems to only fix some of the animations, not all of them.
Is there an accepted best practice for preventing unwanted animations in iOS?

Using AutoLayout, the background UIView hides content on runtime, but not at design time. Why?

I've updated my old pre-AutoLayout view to use AutoLayout. All warnings and errors are gone. I can successfully switch the simulated size to any iPhone and it will work.
However, once I run on actual hardware, the UIImageView that I've set as a background image seems to be hiding all the content (either that or the other content is being pushed off). I've verified that the UIImageView is closest to the root, so it should have the lowest z-index position. When I delete the UIImageView, all the content appears as expected.
If this helps: I've pinned the leading, trailing, top and bottom values of the UIImageView to the superview sides and the respective navbar/toolbar edges.
I've since confirmed it's merely covering the other content by setting a transparency value. So for whatever reason, it's getting pulled to the front. If anyone has intimate knowledge of AutoLayout and has some sane reason as to why that's happening, I'd love to hear it, otherwise, I'll chalk it up to just quirkiness.
I believe the underlying XML of the view had issues.
Solution Summary:
Removed setTranslatesAutoresizingMaskIntoConstraints:NO code.
Re-dragged background image to original position in hierarchy.
Details:
After digging around with the commands that Rob showed me, I was able to confirm that there were a lot of ambiguous layout errors at runtime only. I couldn't see anything inherently wrong with the constraints in Interface Builder, but after redoing the constraints several times and still having no luck, I removed the following from my view controller code:
setTranslatesAutoresizingMaskIntoConstraints:NO
That immediately removed the ambiguity errors.
Why did I put that in there? I have no real good reason other than having read some blogs suggesting to do so. Lesson learned, don't blindly do things.
However, this actually still did not fix the original problem. I reran the program and the background image was still jumping to the front of all sibling subviews even though there were no longer any ambiguity errors.
I was able to send it manually to the back by executing
sendSubviewToBack: against lldb.
and the view looked as intended. With no ambiguity errors remaining I decided to just drag the background uiimageview to a new position in the view hierarchy, then I executed the code. Then I stopped and dragged the uiimageview back to its original position, and executed again. And voila, it was in the proper position. I can only imagine the underlying XML had problems.

iOS UIScrollView fine tuning

In Apple's apps I notice the scrolling is perfect. Everything moves nicely and when you stop, it stops. You can have a huge image and move directly to any spot and it stays there.
I'd like to provide the same UE, but for my apps, if the content exceeds the size of the scroll view (as it should - otherwise what's the point in having a scroll view?) the scroll view never stays put, you have to drag to see content on the edges, then it bounces back and hides it again. Very annoying, especially if there is active content like a button there.
I'm not an iOS expert, e.g. I just found out recently about how critical viewWillAppear is w.r.t. UIScrollView. Is there a concise reference somewhere on how to get perfect rock solid scrolling? (i.e. not Apple's Dev docs!)
Thanks for reading,
Yimin
Are you setting the contentSize property on the UIScrollView?
scrollView.contentSize = CGSizeMake(2000, 2000);
Apple has access to internals which we don't so its products tend to perform better. Scrolling in iOS is basically take it or leave it. Have followed the guidelines in the tutorials and they all have flakey scrolling, in particular the edges aren't always visible when zoomed.

Fast custom animation using CADisplayLink causes stroboscopic effect. How to avoid it?

Scenario:
Horizontally scrolling UIScrollView with reused page views (so that there are only few page viewcontrollers which are being reused similar way like UITableView cells). So that they are able to be updated with new content and reused I need to know exact position of UIScrollView's content view (offset). This works great.
Now I need to implement custom scrolling animation - I mean to programatically move the content view, so that user touches some buttons, and the scroll view scrolls to desired position with this custom animation. The movement can be very quick and very far. I can not use Core Animation for this, as I could not track position during animation (CA reports you only start and end of the movement). So I decided to use CADisplayLink, and calculate each UIScrollView content for each position. This works great too.
The only problem is, that sometimes I see stroboscopic effect - say I am moving the content to the right, and it looks like it is moving to left. If I look at builtin animation within UISCrollView using setContentOffset:animated:, the animation is smooth and nice. Does anyone know, how to get rid of this stroboscopic effect?
Most likely your issue is that timestamp is a double and you're assigning it to a float
Floats have 7 digits while Doubles have 15-16 digits.
So in other words you're experiencing data loss. By using double you should see a silky smooth animation.

Resources