cgpoint

CGPoint relative to view

青春壹個敷衍的年華 提交于 2019-12-02 23:47:42
Consider a screen point (CGPoint) and a view (UIView), which is somewhere inside the view hierarchy (it can be a subview of other views). How can you convert the point to a point relative to the view's coordinates? First, convert the point from screen coordinates to the coordinates of your main window: UIWindow *mainWindow = [[UIApplication sharedApplication] keyWindow]; CGPoint pointInWindowCoords = [mainWindow convertPoint:pointInScreenCoords fromWindow:nil]; Second, convert the point from window coords to view coords: CGPoint pointInViewCoords = [myView convertPoint:pointInWindowCoords

Turn two CGPoints into a CGRect

假装没事ソ 提交于 2019-12-02 22:21:31
How can I, given two different CGPoints , turn them into an CGRect ? Example: CGPoint p1 = CGPointMake(0,10); CGPoint p2 = CGPointMake(10,0); How can I turn this into a CGRect ? This will take two arbitrary points and give you the CGRect that has them as opposite corners. CGRect r = CGRectMake(MIN(p1.x, p2.x), MIN(p1.y, p2.y), fabs(p1.x - p2.x), fabs(p1.y - p2.y)); The smaller x value paired with the smaller y value will always be the origin of the rect (first two arguments). The absolute value of the difference between x values will be the width, and between y values the height. colinta A

How do I add a CGPoint to NSMutableArray?

眉间皱痕 提交于 2019-12-02 18:46:14
I want to store my CGPoint to the NSMutable Array, so , I have method like this: [self.points addObject:CGPointMake(x, y)]; But I got the error, it said that : Incompatible type for argument 1 of "addObject". So, I check out the API, - (void)addObject:(id)anObject anObject The object to add to the end of the receiver's content. This value must not be nil. So, I think the " CGPointMake " can make a Object, but it can't be assigned. What happens? kharrison The problem is that CGPoint is actually just a C structure it is not an object: struct CGPoint { CGFloat x; CGFloat y; }; typedef struct

How do I create a CGRect from a CGPoint and CGSize?

江枫思渺然 提交于 2019-12-02 17:51:34
I need to create a frame for a UIImageView from a varying collection of CGSize and CGPoint , both values will always be different depending on user's choices. So how can I make a CGRect form a CGPoint and a CGSize ? Thank you in advance. Two different options for Objective-C: CGRect aRect = CGRectMake(aPoint.x, aPoint.y, aSize.width, aSize.height); CGRect aRect = { aPoint, aSize }; Swift 3: let aRect = CGRect(origin: aPoint, size: aSize) Building on the most excellent answer from @Jim, one can also construct a CGPoint and a CGSize using this method. So these are also valid ways to make a

IOS: verify if a point is inside a rect

为君一笑 提交于 2019-12-02 14:46:12
Is there a way to verify if a CGPoint is inside a specific CGRect . An example would be: I'm dragging a UIImageView and I want to verify if its central point CGPoint is inside another UIImageView Ole Begemann Swift 4 let view = ... let point = ... view.bounds.contains(point) Objective-C Use CGRectContainsPoint() : bool CGRectContainsPoint(CGRect rect, CGPoint point); Parameters rect The rectangle to examine. point The point to examine. Return Value true if the rectangle is not null or empty and the point is located within the rectangle; otherwise, false. A point is considered inside the

How can I prevent closing Bezier Path

天涯浪子 提交于 2019-12-02 12:09:17
问题 I want to create a Bezier curve, and create a collision boundary for my object. let firstSurfacePoint = CGPoint(x: 30, y: 120) let secondSurfacePoint = CGPoint(x: 20, y: 200) let thirdSurfacePoint = CGPoint(x: 200, y: 300) let center = CGPoint(x: 150, y: 120) let radius: CGFloat = 120.00 let arcWidth: CGFloat = 20.00 let fourthSurfacePoint = CGPoint(x: 240, y: 300) func createCollisionPath(collision: UICollisionBehavior) { let line = UIBezierPath() line.moveToPoint(firstSurfacePoint) line

Tracing the exact location of the longpressgesture with CGPoint

社会主义新天地 提交于 2019-12-02 10:20:29
问题 By using CGPoint location it is always saving the last image in uiscrollview. When i m tapping on other image to save. What can i do to save the exact image one i tapped. UIScrollView *imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; imageScrollView.pagingEnabled = YES; NSInteger numberOfViews = 61; for (int i = 0; i < numberOfViews; i++) { CGFloat xOrigin = i * self.view.frame.size.width; NSString *imageName =

How can I prevent closing Bezier Path

可紊 提交于 2019-12-02 06:14:31
I want to create a Bezier curve, and create a collision boundary for my object. let firstSurfacePoint = CGPoint(x: 30, y: 120) let secondSurfacePoint = CGPoint(x: 20, y: 200) let thirdSurfacePoint = CGPoint(x: 200, y: 300) let center = CGPoint(x: 150, y: 120) let radius: CGFloat = 120.00 let arcWidth: CGFloat = 20.00 let fourthSurfacePoint = CGPoint(x: 240, y: 300) func createCollisionPath(collision: UICollisionBehavior) { let line = UIBezierPath() line.moveToPoint(firstSurfacePoint) line.addCurveToPoint(thirdSurfacePoint, controlPoint1: secondSurfacePoint, controlPoint2: secondSurfacePoint)

Convert CGPoint from CGRect to other CGRect

≯℡__Kan透↙ 提交于 2019-12-01 19:29:07
I have placed one label on view and view's frame is CGRectMake(0,0,270,203) . Now I have to take screen shot of view with CGRectMake(0,0,800,600) . So I have to convert label from old rect to new rect . here is code which I used to take screen shot: CGRect rect = [view bounds]; UIGraphicsBeginImageContextWithOptions(rect.size,YES,0.0f); CGContextRef context = UIGraphicsGetCurrentContext(); [view.layer renderInContext:context]; UIImage *capturedImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); Here is the code which I used to convert point: CGRect f = [view

Image gets blurry and zoomed out when erasing

我只是一个虾纸丫 提交于 2019-12-01 16:27:06
问题 I am using functionality of erasing image and my code is like below. You can see Video HERE. Here current_sticker_img is my Imageview NOTE: I am also using Pan Gesture for zooming image //MARK: Eraser touch event override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { if btn_eraser.isSelected == true || btn_repaint.isSelected == true{ let touch : UITouch = touches.first! lastpoint = touch.location(in: current_sticker_img) } } override func touchesMoved(_ touches: Set