how can I create an NSRect where it is selectable and can be moved around inside a view? Would it be a CGRect or an NSRect to accomplish this? what would I add to:
NSRect viewFrame = NSMakeRect(0, 0, 100, 100);
Would I first have to make it selectable and then use an NSEvent, or could I have the NSRect origin be equal to my mouse position in an NSTracking?
NSRect and CGRect are just structures that contain the data that defines a rectangle. If you want to draw a rectangle on the screen, you'll need to create a view that draws the rectangle. To move that rectangle, you'll tell the view to draw the rectangle in different locations, or just move the view around.
Related
Is there a simple way to add rounded corners to NSRect elements in Objective-C? Currently we're applying a PNG image that simulates corners to this:
NSRect newFrame = NSMakeRect(0, 0, size.width, size.height);
But, performance becomes an issue because there are many instances of this NSRect along with the image being rendered with Core Animation. Perhaps rendering a native NSRect with rounded edges would be better from a performance standpoint? Do said edges look smooth (anti-aliased) when rendered with Core Animation?
NSRect is a struct containing an NSPoint and an NSSize, so I think you mean anything that accepts NSRects (so subclasses of NSView). All NSView subclass layers respond appropriately to -cornerRadius (except something about NSScrollView).
self.view.layer.masksToBounds = YES;
self.view.layer.cornerRadius = 10.0;
I have two rects that intersect. They have the same dimensions, the only difference is that one of them is lower down the screen than the other. I know there is a way to get the rect of their intersection, but that's not what I want. I actually want a new rect from the area that lies outside of their intersection.
The top part of the lower view intersects with the bottom part of the top view. The new rect should not have that area. I basically want a rect with the same origin and width as the bottom view, but without the part that intersects with the top rect.
Thanks for the help.
CGRect intersectRect = CGRectIntersection(highestRect, lowestRect);
CGRect theRectYouWant = CGRectMake(0, 0, 0, 0);
if(!CGRectIsNull(intersectRect)) {
theRectYouWant =
CGRectMake(lowestRect.origin.x,
intersectRect.origin.y + intersectRect.size.height,
lowestRect.size.width,
lowestRect.size.height - intersectRect.size.height);
}
Have a look on this page for more, Elbimio ;)
How do I remove a drawn NSRect or other object other than drawing another rect over it?
Assuming you drew the rect in drawRect:, all you need to do would be to exclude the rect from the list of objects to be drawn and call [view setNeedsDisplayInRect:theRect]. theRect here would be the CGRect equivalent.
I have an application which loads a view in it. I want to position the loaded view in 450pt of y cordinate. How to do that.
Regards
Ranjan
Look at the documentation for UIView and in particular the properties frame, bounds and center
I assume that you are adding a subview so you want it in the coordinate that is relative to the parent view. Then you use frame.
CGRect r = [subView frame];
r.origin.y = 450.0f;
[subView setFrame:r];
Something like that.
I'm trying to figure out what i'm doing wrong but i just don't get it. Here is what i want to do:
I want to draw a circle somewhere on the screen of the iPhone and then i want the circle always to be displayed at the position where the user currently taps on the screen.
I started by creating a subclass of UIView and adding the following lines into the "drawRect" method:
- (void)drawRect:(CGRect)rect {
//Create the main view!
CGContextRef mainscreen = UIGraphicsGetCurrentContext();
//Draw the dot
//will be a circle cause rectangle is a square
CGRect dotRect = CGRectMake(50, 80, 100, 100);
[[UIColor blueColor] set];
CGContextStrokeEllipseInRect(mainscreen, dotRect);
CGContextFillEllipseInRect(mainscreen, dotRect);
}
The appears just fine but now I have no idea how to make it move around on the screen I've tried several things and nothing worked.
To draw the dot in a different location, change the origin of dotRect. To figure out where to draw it, implement -touchesBegan:withEvent: and -touchesMoved:withEvent: and record the location where the touches are occuring.