Not drawing outside bounds when clipToBounds=NO - iphone

I am drawing lines on a map, and I notice that my annotation view isn't covering the entire area of the lines (which is fine, as long as I can draw outside the bounds of the view).
Here is a picture of what I'm experiencing. The clipToBounds property is set to NO for the annotation view, and I've added a semi-transparent color to the background so you can see the position of the view.
blue line not drawn outside bounds http://img.skitch.com/20100512-qdm18j7x42wptw3cumnr6h271q.jpg
The pins represent the various waypoints on the map.
Do I have to do something special to get the lines to keep drawing outside the bounds of the view?

What lines are you referring to?
Anyway, I think the answer should be "no", unless you are doing custom drawing.
In that case, you need to make sure [view setNeedsDisplay] is being called whenever the lines need to be drawn.

Related

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.

Creating a bounding box for a View

Is there a way to a bounding box for a view so that its subviews cannot leave the view?
I currently have UIImageViews which I move around, scale, rotate etc and they are able to leave the view area.
How does one set the superview to bound/hold the subviews within it?
How else can this be done. I currently detect the origin of the image this works to the point that the image moves until it reaches this origin, when it does, the image is stuck.
I use gestureRecognizers and this origin technique only works for panning/moving an image.
Any suggestions?
If you want to stop a view's subviews from being drawn outside its borders, you need to set its clipsToBounds property to YES. (See the UIView class reference for details.)
If you want to stop your views from being in certain positions, don't move them there! It's your code that's putting them where you don't want them to be. If you're using a gesture recogniser, presumably you have a method that responds to gestures by adjusting the frame of a view - put some conditions on this movement that prevent it from happening when you don't want it.
When you write these conditions, bear in mind that a view's origin is relative to its superview. For example, say you have a view controller with a view that takes up the whole screen of the device, and inside that a box that starts at 0, 100, and inside that some squares and circles and squiggly shapes that the user can move around. If you examine containerBox.bounds.origin, you'll find that it's 0, 100, but if you want to put a square in the top left corner of the box, you need to get its frame and set the origin to 0, 0. Something to look out for.
I didn't follow your explanation of the 'origin technique'. If you paste your code, I might be able to help.

draw outside of UIView's bounds from drawRect

My question is very similar to this one Not drawing outside bounds when clipToBounds=NO which received no clear answer.
Basically I have a UIView, and I want to draw a line from the center of it, to the edge of the screen. Calculating where these points are is easy, using [self convertPoint:(CGPoint){0,0} fromView:[self superview]]; (which finds the origin with respect to my view's superview. But when I draw a line from my view's drawRect: it gets clipped at my view's bounds.
Is there a way to draw outside of my view's bounds? I've tried changing the clipsToBounds property, but it doesn't seem to have any effect.
I can't draw my lines from the superview because I need to do this with multiple views and some will be in front of others... figuring out the layer from the superview's drawRect seems like a bad idea.
Similarly, I don't think I can just resize my view's bounds to include the entire screen, because my views need to be dynamically re-sizable... the bounds would have to be HUGE (>20,000 points square) for this to work.
I wouldn't recommend ever drawing outside of a view's bounds. Either your view needs to resize automatically to include your drawing or you need to have transparent overlapping views. Or both. I can't think of a situation that either of these cases wouldn't cover, but I may lack imagination. =)
Likely what is happening currently is that when the super view gets redrawn it tells the super view that it needs redrawn, resulting in erasing the drawing you are doing outside. It's been a while, anyone more knowledgeable can (should!) correct me here if I'm wrong.
I don't know if "Quartz Debug" (from the standard apple developer tools install, /Developer/Applications/Performance Tools/Quartz Debug) works in the simulator, but it's worth a try. It has a mode that will show you when and how often redrawing takes place, with a border and optional delay on the refreshes.
You can do what you are asking, but you need to force redraw your sub-views every time you go outside the sub-view's bounds, meaning that your super-view needs to manually draw it's children inside of it's draw function. Essentially you would be throwing out apple's drawing paradigm and simply causing your sub-views to act like a drawing extension of your main view anyway.
Additionally, if your ranges are so dynamic you may want to consider drawing in percentages of the screen or super-view rather than in points, it may make more sense to code.

draw line/point on existing UIView without drawRect?

I created line chart. Now I need to display point on this chart when I tap the screen.
What would be the best method? Do I need to call drawRect method again, draw whole chart with marked point?
I'm thinking about something like transparent layer over the chart UIView.
Can I create another transparent UIView and put it on the position of my chart?
Since all drawing is done in a view's drawRect: you can only optimize your chart's drawing so it can be made to update only a part of it and use setNeedsDisplayInRect: (passing the area where the marker should be).
Or you create another UIView subclass that is layered atop of your chart and that does nothing but drawing the markers on a transparent background. Probably easier and faster to implement. It also would have another benefit:
If you make that view only as big as the bounding box of the marker you could also easily animate it, like fading it in and out. Or letting it rotate a little (to see the effect I have in mind, select the "Help" menu in Mac OS X, type something in the search field like "a", and see the marker next to a menu item move a little around a spot).
You can draw a portion of your view using setNeedsDisplayInRect:.

My Quartz drawing on iPHone is clipped after rotation!

I'm drawing three rectangles, one of which falls off the end of the view, (i.e. the drawing is bigger than the current view bounds) so you don't see the right edge. This is good, but when the view is rotated, the right edge is still clipped, even though there's plenty of room to draw it. How can I get the view to redraw the full rectangle?
I've tried:
1) changing the frame and bounds rectangles to bigger
2) calling setNeedsLayout
3) calling setContentMode:UIViewContentModeRedraw;
4) calling [self.view setClipsToBounds:NO]
Trying a CGLayer is next, unless somebody suggests something else.
-Owen
Make sure your autoresizing mask on this layer is set properly in IB. If its not stretching the right way on rotation then the view will not take the new shape of the screen.