Reputation: 503
I have UIView with a sublayer attached to the layer of UIView. UIView has the @IBDesignable-tag and is perfectly shown in the storyboard.
However if I launch the application in the simulator the sublayer does not show up. I don't get any error messages, the sublayer just doesn't show.
Does anyone have an idea how I could debug this problem or any other idea about the cause ? I tried to debug it with the new "Debug View Hierarchy"-Button in the debugger's toolbar, but unfortunately it shows only the views and not the layers !
Here is my configuration:
Here in dropbox you can find the Xcode-project: https://www.dropbox.com/s/uejq7j74qyx715x/ArcProblem.zip?dl=0
The view causing the problem is called "RotateMeterView.swift"
Upvotes: 2
Views: 2049
Reputation: 503
The Problem is finally solved: I opened a TSI with apple. it came out, that it was a Programming error from my part. Please find here the answer provided by Apple:
You should not be using the frame of view to calculate the position of subviews. In fact you should never access a view's frame from within the view itself. Instead, use the bounds property which returns values in the current view's coordinate space. See the View Programming Guide for iOS for more information.
So this line:
circleLayer.position = CGPoint(x:CGRectGetMidX(frame), y:frame.origin.y + frame.height - radius - dy)
should become:
circleLayer.position = CGPoint(x:CGRectGetMidX(bounds), y:bounds.origin.y + bounds.height - radius - dy)
Also, you should not be positioning and sizing subviews in a function that will only be called once at view load. View sizes can and do change after they are loaded (e.g. during rotation). Your view should be overriding -layoutSubviews
and positioning the circleLayer there.
Upvotes: 5