NSView equivalent of UIView Clip Subviews? - nsview

Is there a way to disable clipping of subviews of NSView? In UIView there is a “clip subviews checkbox” and the backing clipToBounds property, but I cant find anything similar in Cocoa.
Here is my scenario: I have this grey dot that you can drag on the screen:
When the user drags the dot I want to show up and down arrows that I have in the background. The up arrow is outside the bounds of the NSView holding the dot and arrow.

You could use the [NSView frameForAlignmentRect:] method. It defines the frame which is used for the constraints based layout. The actual frame can be much larger to allow displaying the arrows when the view is moved.
Cocoa is using this feature to compensate for shadows or other parts of views which do not "count" as actual frame of a control.
From the documentation:
The constraint-based layout system uses alignment rectangles to align views, rather than their frame. This allows custom views to be aligned based on the location of their content while still having a frame that encompasses any ornamentation they need to draw around their content, such as shadows or reflections.

Related

AppKit: How can I remove one pixel inset of NSOutlineView

I'm totally new to AppKit. I'm so confused about managing layout of AppKit views.
I have a view which frame is 450*300
and I added an outline view in the view but it has one pixel inset automatically added.
This makes a one pixel border and it makes me annoying.
I can't fix it at all. There's no options about insets, constraints and resizing frame. What I wanna do is just making outline view's size the same as the super view's size so that there's no tiny border.

Keeping UIViews visible only within a limited area of the screen

Is it possible to make a UIView only appear inside a limited area of the screen, especially while animating? (When it reaches the boundary, it should simply cut off at the boundary point, as if it were being obscured by an object in front of it.) I need this because I have a roll-out menu comprised of UIButtons, and I don't want the menu to extend beyond the edge of the toolbar when closed. Thank you!
(Alternatively, hiding the entire UIView upon reaching the boundary would also be acceptable. I just don't know how to check for this condition without continuously querying the center property.)
You can define a clipping area for your UIVIew using the clipsToBounds property. If you are using CoreAnimation to animate your view, you may want to have a look a the maskToBounds property of CALayer objects as well (each UIVIew has a layer property of type CALayer).
From the UIView Class reference:
Normally, a subview’s visible area is
not clipped to the bounds of its
superview, but in iOS you can use the
clipsToBounds property to alter that
behavior.

How to auto rotate your own custom views?

I've learned that the best way to get graceful rotation is to set the auto rotation mask on the view that you want resize or move. This works fine if you're using SDK views like UILabel, but if you have your own custom view that uses the drawRect method it doesn't rotate as gracefully. In fact the only thing that happens is that it stretches whatever you drew in drawRect.
I've tried redrawing both before and after the rotation, but it doesn't give me that smooth rotation.
I looked at a UITextField auto rotating (flexible width) in slow motion and it follows the edge perfectly during the rotation. That is what I want my view to do, so how do I do that? My views jump to the right position either before or after the rotation.
The following line will make your UIView stretch the middle pixel only. If this is not your desired behavior I suggest you read the documentation for contentStretch to learn how to manipulate the values of the CGRect.
[self setContentStretch:CGRectMake(0.5, 0.5, 0.0, 0.0)];
I would guess that the UITextField you're looking at has at least three subviews, one displaying the left cap of the field's border, one displaying the right cap, and one displaying the middle, with autoresizing masks of "flexible right margin", "flexible left margin", and "flexible width", respectively. If you set up your custom view something like that, and make sure its autoresizesSubviews property is set to YES, then you should get the same smooth resize that the text field does.

iPhone SDK, selection Rectangle around a view

I have a Drawing app of sorts and am looking for some feedback on ways to draw a selection rectangle, and or the resize grips for a selected view.
So I have a custom class that is inherited from UIView, in it it contains a UIImageView, UILabel, and UIButton. I can have several on the screen at one time. I want to tap on one and draw a selection rectangle around it. From there if i drag I want the view and the selection rectangle to move with it. I would like the Selection Rectangle maybe 4px larger than the exiting bounds rect.
So my question is what is the best way to get the Selection Rectangle around the selected UIView object?
Do I offset the object so what when I add in the UIImageView, UILabel, and UIButton that are part of it I have a 4px buffer around the edges?
Do I adjust the View when selected to reposition the subview, increase the bounds and offset the frame?
Do I just create a new UIView that is 4px larger than the selected object and just move it with the selected view?
Do I just create a new UIView that is 4px larger than the selected object and and make the selected view a subview of it?
or? (your Idea Here...)
Thank you for your comments and Suggestions...
Scooter133
Consider setting the borderWidth property on your view's layer. Note that this is drawn within the view's bounds, so it may be more useful as a highlight state than a selection rectangle.

Apply barrel distortion to UIView

I've got a UIScrollview which fills a landscape screen, which contains a small tree of UIViews around inside it which I can scroll horizontally. I'd like to apply a barrel distortion to the scrollview, so that as the subviews move from the outside to the centre of the scrollview, they change shape.
What is a good what to go about applying distortions like this?
Is there a way to override drawRect for the scroll view, draw onto a bitmap, distort it, then draw that to the ScrollView's context instead? Or are there built in APIs to do this sort of distortion?
(source: arielnet.com)
You could get close to this effect by properly transforming the layers for each of your UIViews. Using a CATransform3D, you can rotate and translate each of the layers in 3-D, as well as apply a perspective effect. For your case, you can translate each of your UIView layers so that they are like a carousel, with the middle view forward and straight-on to the screen, and the side layers tilted and recessed slightly from the screen. This would not cause a curvature of the layers themselves (they will still be drawn as rectangles), but if you apply a transform on the main view's layer to create a perspective effect you should be able to get very close.
For an example of this kind of 3-D positioning of layers, I recommend this example where a full 3-D maze is constructed out of CALayers.
As far as the scroll view goes, you probably will have to do custom touch handling for this. You might be able to get by with respinding to the UIScrollViewDelegate methods like scrollViewDidScroll:, but I've not tried this myself.