Animating only part of a UIView drawn context? - iphone

I am drawing some text and images to a view in the "DrawRect" method.
I wish to understand :
does my drawings are separated objects?
i know how to animate UIViews but how do i reach one of them so i can animate his properties ?
thanks
shani

O.k
if any one wants to know the answer. you can not animate drawn text or objects unless you draw it to CALayer.

Related

Hide / reveal UIImage based on finger path?

I hope that makes sense. I'll try to explain it.
I have a UIImageView on screen, and am wondering how I can take the area after "drawing" on it with a finger, and remove that section from the UImage, or, create a separate UIImage from the selection.
I'm not looking for code (unless you have it =] ), just an idea of how to go about doing it. If you have tips, I'd be very grateful, thanks.
If I understand your question,
I think I would add a transparent UIView as a subview over the top of the UIImageView. And draw on that. Then you can remove/hide the subview when your done.
you need to create a UIGestureRecognizer with target and a action like -imageIsPressed, in this -imagePressed method you can call something to make the image disappear. I would suggest placing the UIImage into a UIImageView and calling imageview.hidden = YES; to hide the image, and set it back to "NO" once its not held by the finger.
You'd need to implement something that captures the area the user 'selected' (maybe be creating a CGPath. Then you create a CALayer of the size of the imageView. In it you create, draw and fill the captured path with some arbitrary color while leaving the rest transparent. Finally you apply your generated CALayer as a mask to the UIImageView:
imageView.layer.mask = maskLayer;
Hope that gets you started.
For more info on how to draw that custom CALayer pls refer to Quartz Programming Guide
So basically you want to implement freehand erasing of an image? You will need to use core graphics and the various CGContext methods (with blend mode set to clear) to achieve this. There are two approaches, but both start with drawing your image as the first part of drawRect, and then
1) Store your strokes in an array, and stroke all of them over top of the image.
2) Stroke one stroke over the image and then store the resulting image into a UIImage. Use this UIImage as the next image that you draw in drawRect. This one is difficult for undo/redo functionality.
I recently implemented this myself and made the source available here. Basically I used the same methods described here with this change when setting up the graphics context:
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeClear);

iPhone: In a custom view, how to draw something on top of everything else in the view?

So I made a UIView subclass let's called it 'MyView' that simply draws a line inside the DrawRect method.
I then drag a UIImageView in interface builder and put it inside MyView. But now when I run the program it's obscuring the line that I'm drawing. I'm wondering, is there a way for me to draw the line on top of the image that I have dragged into my View?
No, you'll have to reorganise the view hierarchy. CoreGraphics uses a painters model so views behind will always be drawn over by views infront. To solve this you could use a container view that holds your image view and has a transparent view (line drawing view) that sits over the image view.
Another option is to draw the image using core graphics calls in your drawRect method and then draw the line over it.
One way is to have whatever adds MyView to add your UIImageView on top of MyView. It's not ideal (you probably have good reasons for keeping MyView and the UIImageView in a single class) but definitely solves your problem (I recently did this, only, I added it to the keyWindow =)
I would use a CAShapeLayer that has a path representing the line, and insert that layer ahead of the built-in view layer. Then it should draw on top.

Stretchable UIImage and CGAffineTransform

I've got a UIScrollView whose zoom behavior I want to confine to the horizontal axis. I've accomplished that through using a custom UIView as the viewForZoomingInScrollView: and overriding setTransform:. So far so good – the view only zooms horizontally.
One catch: The container view includes some stretchable UIImage instances in UIImageViews. Obviously, with the transform in effect, the images distort.
What's the best bet for either redrawing the view so that the images aren't distorted, or, zooming the view in such a way as to not require transforms in the first place?
Thanks for any help you can offer.
You sure way of achieving this is to make your UIImageView into a custom UIView, and have its drawRect: code do the right thing: draw both stretched and unstretched elements.

Shadow inside UIView

I am working on iPhone application development and have come across shadows of UIView.
I know how to show shadows to a UIView but what I am actually interested in is to drop shadow inside the UIView.
Like when I set shadow properties of a UIView the shadow is dropped behind the view. I want it to come over the view so that the view looks as if it is pressed inside.
Example of such view is UITextField with roundedRect styling.
Thanks,
It depends a lot on the final effect you want to achieve.
The easies way would be a custom image with a prebacked shadow as background. This will give the illusion of a recession in the surface of the view. You can then add subviews to it as usual.
Alternatively, you can override the drawRect: method and draw the view as you like there, "inverted drop shadow" included.

Most effective way of drawing 4 lines in an iPhone app?

basic question, but I'm unsure. Not looking for code as an answer.
I want to draw 4 short lines 1px lines on a view. What is the best way to approach this task? Options:-
Load an image of the line, then create 4 UIImageViews with it.
Create my own subclass of a UIView that draws a line in the draw rect method.
Draw elsewhere on another view, another UIImageView that has an UIImage inside it (is this possible?)
Another way?
Thanks
Ross
Simplest way is to create a UIView subclass and perform your drawing in drawRect:. See the CoreGraphics guide for details on how to draw a line.
Quick and dirty way to achieve this is to just create a UIView and set it's height (or width, depending on its orientation) to 1px, and then set a background colour and slap it onto your view as a subview.