Why i can't using UIBezierPath class in UIViewController class directly without using any View class ?
Because you can't draw on a controller, you draw on a view. To demonstrate, If UIBezierPath class is a pen, the view is your paper and the code you put in the view's dreawRect() method is like your hand which uses a pen (UIBezierPath) to draw.
The viewController is so unrelated that you can say its a bag for your papers.
Related
I know a method to draw on iPhone using UIView class and UIImage method. But can i draw inUIViewController class on UIImageView?
As UIImageView is a subclass of UIView, you should be able to use the exact same method to do what you want.
You might also add a custom view (inherit from UIView) above any other view and draw anything you want on that view.
I'm creating methods to use multi-touch taps to draw shapes on top of an image inside a UIScrollView. I'm thinking that I should just create a new UIView subclass for the shapes and add them as a subView to the main controller that contains the scrollView.
If so, can I simply use touchesBegan, touchesMoved, ... with the new UIView subclass? And if not how do I connect the touches to the drawing logic.
Thanks!
To get the touch method in UIScrollView you need to make your own class for Scrollview which is sub class of the UIscollview and use that class in place of the UIScrollView. As you class is Sub class of UIScrollView you can get all the method of the UIScrollView through object of you class.
Now for getting touch method you will get in you class and using custom delegate you can call in any class.
I have a UIView subclass. This subclass has multiple subviews. Is it possible to draw a line using core graphics inside a subview that is part of the uiview subclass?
For example, I have a SampleView class, which is a subclass of UIView. Inside this class's header file is the property for UIView *sampleSubView, which is a subview of SampleView. Is it possible to draw a line inside of sampleSubView from the SampleView class implementation?
Thanks for your help!
Josh
If you are asking how a UIView subclass can draw a line on itself, then see the Quartz demo sample code. Basically, you'll override the view's drawRect: method, get the current graphics context, then draw whatever you like onto it.
If you are asking how one view can draw a line on another view, perhaps you need to rethink your architecture.
I have a UIViewController in which I want to draw a square. So do I need to create a UIView for that and add the created view to my viewControllers view.
Like Is there any way to do that or can I override the drawRect: method for my controllers view to draw that square.
Draw rect draws the rectangle which becomes the views frame, you can draw the Square in viewDidLoad tho
A view controller owns, but is not, a view. Add a view to the self.view of the view controller. Add your view in or after viewDidLoad is called in the controller.
For the specific case of a filled square or rectangle there is no need to draw anything. Just set the background color and frame of the new view.
Error is like this:-
errror:-CGAddLineToPoint invalid context
I assume by EAGLView, you mean a custom UIView subclass that is backed by a CAEAGLLayer. Because such a view has its content drawn by the OpenGL layer, you can't do the same sort of Quartz drawing within it that you would in a UIView backed with a standard CALayer.
My recommendation is to move your custom Quartz drawing to another UIView subclass, and place that UIView as a subview of your CAEAGLLayer-hosting view.