cgpoint

Get random CGPoint on CGPath

柔情痞子 提交于 2021-02-07 09:12:55
问题 I have a CGPath that represents an ellipse. I'd like to place a sprite node at a random point on that path. How can I get a random CGPoint on that CGPath? 回答1: Speaking about a closed CGPath and thinking to a fast method to obtain a random point between infinite points inside a CGPath , first of all I've translated to Swift this: extension CGPath { func forEach(@noescape body: @convention(block) (CGPathElement) -> Void) { typealias Body = @convention(block) (CGPathElement) -> Void func

Get the max and min values from an Array of CGPoints

时间秒杀一切 提交于 2020-05-17 08:50:49
问题 We have an array of CGPoints: let points = [(1234.0, 1053.0), (1241.0, 1111.0), (1152.0, 1043.0)] What I'm trying to do is get the CGPoint with the highest x value and the one with the highest y value in the array. I will be using these points to create a CGRect: extension CGRect { init(p1: CGPoint, p2: CGPoint) { self.init(x: min(p1.x, p2.x), y: min(p1.y, p2.y), width: abs(p1.x - p2.x), height: abs(p1.y - p2.y)) } } I know there a way to get max and min values in an array by doing something

Get the max and min values from an Array of CGPoints

不羁的心 提交于 2020-05-17 08:50:08
问题 We have an array of CGPoints: let points = [(1234.0, 1053.0), (1241.0, 1111.0), (1152.0, 1043.0)] What I'm trying to do is get the CGPoint with the highest x value and the one with the highest y value in the array. I will be using these points to create a CGRect: extension CGRect { init(p1: CGPoint, p2: CGPoint) { self.init(x: min(p1.x, p2.x), y: min(p1.y, p2.y), width: abs(p1.x - p2.x), height: abs(p1.y - p2.y)) } } I know there a way to get max and min values in an array by doing something

convertPoint:fromView: works well on the simulator, not on device

十年热恋 提交于 2020-01-16 19:28:06
问题 I was happy to see this: answer for how to convert point of a subview and it worked perfect for me on the simulator. But for some reason it doesn't work on the device... Can it be that the views positions are differently managed by the device - or is it just another mystery? Or (hopefully) I wrote it wrongly and you guys can help... :) here's my line: CGPoint yoel = [imagePressed.imageView convertPoint:imagePressed.frame.origin toView:nil]; 回答1: I had a different problem that relates to this

convertPoint:fromView: works well on the simulator, not on device

本小妞迷上赌 提交于 2020-01-16 19:27:31
问题 I was happy to see this: answer for how to convert point of a subview and it worked perfect for me on the simulator. But for some reason it doesn't work on the device... Can it be that the views positions are differently managed by the device - or is it just another mystery? Or (hopefully) I wrote it wrongly and you guys can help... :) here's my line: CGPoint yoel = [imagePressed.imageView convertPoint:imagePressed.frame.origin toView:nil]; 回答1: I had a different problem that relates to this

How to Programmatically Scroll iOS WKWebView, swift 4

我怕爱的太早我们不能终老 提交于 2020-01-15 09:43:34
问题 So my question is: After a website(any websites on the www) has been loaded up in my iOS webview app how to make the app Programmatically Scroll vertically to any of the contents thats out of view? // ViewController.swift // myWebView import UIKit import WebKit class ViewController: UIViewController, WKNavigationDelegate { @IBOutlet weak var myWebView: WKWebView! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. }

Distance between two rectangles

北慕城南 提交于 2020-01-13 19:09:03
问题 How can I find the distance between two rectangles? Intersects should return 0 in distance. 回答1: Here's a quick function for calculating distance between two CGRects represented by a CGSize: CGSize CGSizeDistanceBetweenRects(CGRect rect1, CGRect rect2) { if (CGRectIntersectsRect(rect1, rect2)) { return CGSizeMake(0, 0); } CGRect mostLeft = rect1.origin.x < rect2.origin.x ? rect1 : rect2; CGRect mostRight = rect2.origin.x < rect1.origin.x ? rect1 : rect2; CGFloat xDifference = mostLeft.origin

How do I properly observe the contentOffset property of my scrollView subclass?

大城市里の小女人 提交于 2020-01-13 09:21:14
问题 In my iOS app I am observing changes to the contentOffset property of my scrollView subclass. My observer handler looks like this: - (void)observeContentOffsetHandler:(id)aContentOffset { NSLog(@"%@", aContentOffset); } I chose the parameter to the method arbitrarily as an id for simplicity. My NSLog'ging looks like this: -[MyScrollView observeContentOffsetHandler:] [Line 111] NSPoint: {296, 375} -[MyScrollView observeContentOffsetHandler:] [Line 111] NSPoint: {296, 389} -[MyScrollView

How to get Lat Long of tapped location in Google Map iOS Swift

你。 提交于 2020-01-07 02:51:22
问题 I am trying to get the CLLocationCoordinate2D object from the tapped location in a google map view. But it always return me -180.0, -180.0 as lat,long like this: CLLocationCoordinate2D(latitude: -180.0, longitude: -180.0) I am using following code for this: override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { let touchpoint = touches.first if let touch = touches.first { var point: CGPoint = touch.locationInView(self.view) let touchMapCoordinate:

moving CGPoint a certain distance along a certain heading…iphone

倾然丶 夕夏残阳落幕 提交于 2020-01-04 02:17:13
问题 this seems like such a simple problem but I have been unable to find an answer (and im no good at math). I am trying to move a UIView to a new CGPoint X distance away along a certain heading. What is the formula for determining the new coordinates? (i do no want this to be animated, just an instantaneous move) something like: x = 100; (current x value) y = 150; (current y value) d = 25; (distance to move the point) h = 90; (west) \\\ insert formula to determine new x,y coords self.car.center