511 questions
0
votes
0
answers
79
views
Seeming inconsistency in Swift - why does this work with CGPoint but not with CGFloat?
extension CGPoint {
var coordx : String {
let xx = round(x * 10 * scaleFactor)/10 //No problem here
return "\(xx)"
}
var coordy : String {
let yy = ...
0
votes
1
answer
41
views
Having trouble converting point that's on a rotated view with a (0, .5) anchor point
I have the following view set up:
Where the anchor point for V3 is (0, .5) and it can be rotated by a UIPanGestureRecognizer that's attached to V4. I'm trying to translate a point on V4 to V1s ...
0
votes
0
answers
150
views
iOS Swift How to warp part of image from detected source point to destination point?
I’ve detected specific part of image (blue ball) and I need to warp this part from upper-point to lower-point. I’ve found WarpGeometryFilter but the problem is that it warp full image to point of ...
0
votes
2
answers
258
views
How to make a Line follow a CGPoint in SwiftUI?
I've created two CGPoints and a connecting line between them. My aim is the following: When I drag the second CGPoint with a SwiftUI DragGesture() the line will follow it (as if it's connected to it). ...
1
vote
2
answers
351
views
iOS - Get CGRect around CGPoints
I have array of CGPoint indicated in red. I must connect all consecutive points with CGRect as shown in the rough figure to form an array of CGRect. Consider all rect has a constant width and each ...
0
votes
2
answers
260
views
Swift. UIBezierPath shape detection
I working with UIBezierPath and shape detection. For painting im using "UIPanGestureRecognizer".
Example of code:
My shape definder
var gesture = UIPanGestureRecognizer()
.
.
.
view....
2
votes
1
answer
94
views
Why does a node's position change when a CGFloat is used instead of a numeric literal?
Goal
I want to set the position of a child node in my game's scene using the position property of SKSpriteNode and pass an inline mathematical expression as the argument to the y parameter. The child ...
1
vote
1
answer
273
views
How to Add Line between two UIView centers in Swift?
As you can see in the Image attached, there are red and green Views on the screen, I want to add a Line between them. How can I do that?
0
votes
1
answer
1k
views
How to centre rectangle in view
I want to centre a rectangle in a view, i try using midX or midY but the view still not centre
this is how i setup the rectangle
the overlayView have width = 414 and height = 688
override func ...
0
votes
0
answers
71
views
how to always show all draw lines?
in my code, I can draw a line by following user touch.
the issue is whenever I draw another line, the previous line is gone. how can I always show all lines?
please guide me for the same.
CanvasView....
0
votes
1
answer
1k
views
Animate a line between two points - swift
I have a class called CategoryCell which us UICollectionViewCell.
On the CellForItemAt function:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> ...
1
vote
1
answer
2k
views
Current coordinates of a tableViewCell swift
fellows!
I'm trying to make an animation of an image in my tableViewCell. My intent is to get an imageView that is in a tableViewCell, add it to exactly the same place in a view, and then use scale ...
1
vote
1
answer
770
views
Find points between two CGPoints
Trying to find nearest points between start and end point.
Points Array :
let pointsArray = [(10.0, 10.0), (70.0, 10.0), (10.0, 200.0), (70.0, 200.0), (73.0, 10.0), (133.0, 10.0), (73.0, 200.0), (133....
0
votes
1
answer
108
views
How to get the UIAction's position on the screen?
In the below UI, I need to show Spotlight where we are going to show some feature of the button from UIAlertController.
So to add a mask to the UIWindow for that button I need it's exact location.
How ...
0
votes
1
answer
315
views
Getting frame from graphed UIBezierPath in Swift
I have created a graph drawing points and creating a UIBezierPath between those points, but now I want to add a gradient to the plotted lines (similar to picture). The issue is I need a frame for the ...
-2
votes
1
answer
197
views
What libraries do we need to include to use CGPoint and arc4random()?
It's my first program in Swift.
The function returns two random locations (CGPoints) which are points on the perimeter of a circle of radius = variable (passed in by the calling program).
The two ...
1
vote
1
answer
69
views
SpriteKit weird behaviour of SKSpriteNode property
I'm moving my first steps into SpriteKt and found this apparently weird behaviour of the SkSpriteNode.position property: it should be a CGPoint, but when assigned and read back, it behaves differently ...
3
votes
1
answer
3k
views
SwiftUI: Convert from a CGPoint on screen to a CGPoint in a view
I have a view placed somewhere in my ContentView. I want to be able to drop images onto it. So I've added and .onDrop to it. In UIKit, I would use universeView.convert(point, to: targetView). How do I ...
0
votes
1
answer
745
views
iPhone back camera cannot focus correctly
I've been making an iOS camera app and trying to solve this problem for two days (but cannot solve this).
What I'm working on now is change the focus and exposure automatically depending on the user's ...
3
votes
2
answers
798
views
Converting NSPoint to CGPoint using NSPointToCGPoint
How difficult can it be to access x and y coordinates from NSPoint ... Can't believe it.
I get an NSPoint from following call:
var mouseLoc = [NSEvent .mouseLocation]
I need to access x and y ...
-1
votes
1
answer
212
views
how to undo last draw stroke in imageContext
I want my swift code to undo the last drawn stroke. I have seen something like the use of PopLast() but connecting that with image view pic does not work. To do the drawing I am using GetImageContext. ...
0
votes
0
answers
155
views
remove all drawing in imageview UIGraphicsGetImageFromCurrentImageContext
I want to remove everything written imageview pic. I have tried something like pic.Clear() but its not being recognized. I dont know what else to do. The only other thing I can think off is to somehow ...
0
votes
0
answers
177
views
Swift - get random CGPoints from UIView
I am trying to get random CGPoints along the 'outer contour' of UIView so that I will be able to draw UIBezierPath line over obtained CGPoints. For example, get CGPoints from below red dots which I ...
0
votes
1
answer
54
views
line disagreeing when touch end when drawing line
My swift code goal is to just draw lines on a image view. Right now when you pick up your hand from the image view the drawing disapers. When your hand is pressed down it works its just when your hand ...
4
votes
3
answers
674
views
How can encode array of CGPoint in Swift
Hello I found nice solution without array from here works OK
@propertyWrapper
struct EncodablePoint: Encodable {
var wrappedValue: CGPoint
enum CodingKeys: CodingKey {
case x
...
1
vote
1
answer
868
views
draw line using uibezierPath in a vertical way
My swift code below draws a horiziontal way the horizontal line is at a angle that does not change. Think like a x axis. I want to draw a line in the exact opposite way. Think of the y axis. The line ...
3
votes
2
answers
436
views
Determining if UIView in array of UIView's overlap with each other at all, and then adjust position
I have a loop below that is supposed to detect if a view in an array of UIView's overlap with each other at all. If they do, then adjust their center value.
Each view is 25x25.
func drawCircles() {
...
3
votes
1
answer
1k
views
Add the middle point between two coordinates on a cgPath
We have a function that creates a path based on an array of CLLocationCoordinate2D, this array contains 4 coordinates, and will create a path with the shape of a square:
func createPath(coordinates: [...
0
votes
1
answer
352
views
getting position of right click in macos app
I'm working on a macOS app with SwiftUI that should be able to create, arrange and delete geometric shapes on screen. The creation and dragging of shapes already works pretty well using a context menu....
0
votes
1
answer
90
views
Passing CGPoint position to another ViewController - Swift - Programmatically
I have 2 viewControllers:
VC1
VC2
(VC2 presented on top of VC1)
I need to know in advance the (CGPoint) position of a subview of VC1 whenever I am in VC2 so that I can apply an animation dismissing ...
-5
votes
1
answer
358
views
Cannot convert value of type int to specified value CGPoint
I have some code that is supposed to swipe a sprite in any direction taking in an initial value of a CGPoint.
I tried setting up a variable for this as
var initialLocation:CGPoint = 0
I know this ...
-3
votes
2
answers
1k
views
Create Array of CGPoints in Swift
I have code that loops through an array of doubles and creates a CGPoint from the double and the index of the array.
However, I can't figure out how to place the resulting CGPoints into an array. ...
1
vote
4
answers
171
views
Programmatically supply argument to cgpointmake or cgpoint to create cgpoints from coordinate pair
Please forgive this naive question, but is there any direct way to create a cgpoints from a coordinate pair without extracting the x and y value separately.
I know you can do:
CGPoint point = ...
-1
votes
1
answer
343
views
Convert JSON array of numbers into CGPoints in Objective-C or Swift
I am trying to convert JSON from an API into an array of cgpoints that I can use in core graphics.
The JSON looks like:
{"date":"2017-01-05","open":119.34,"high"...
-1
votes
2
answers
996
views
create center anchor point of object
My swift code below is trying to rotate a imageview around another imageview. I want the rotation to work just like a game spinner. A link to something close to what I am looking for is https://www....
0
votes
0
answers
160
views
How to convert touch point to CG vector
I'm trying to get the player to move to the direction of the player touch without stopping, or direction of swipe would be better because it seems more natural. However I only can find out how to do ...
1
vote
1
answer
1k
views
How to rotate a image from a specific anchor point
I want to rotate a image in this code would be pic1. I placed a image below of what I am exactly looking for. I don't want to rotate the entire image I want to rotate from the bottom left corner of ...
0
votes
1
answer
1k
views
Swift -Position new UIWIndow in center of Screen
The user taps a cell, I get the touchLocation, create and then animate a new UIWindow to the center of the screen. The problem is when the new window (purple) appears on screen instead of its center ...
3
votes
2
answers
1k
views
How to get a centerpoint from an array of cgpoints?
I 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 find the center of the CGPoints. So I can place an object at the center of ...
3
votes
3
answers
2k
views
Get the max and min values from an Array of CGPoints
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 ...
0
votes
1
answer
280
views
How to calculate height/width based on CGPoint positions
I have an array of 3 CGPoints, what I'm trying to do is create a CGRect based on those CGPoint coordinates. I need this CGRect to set the bounds of a view so it can "zoom in" to those coordinates as ...
0
votes
1
answer
91
views
space position objects by proportion
My swift code below is positioning objects. I want both objects to be to cover 10 percent of the x axis each. So the first object which is fight[0].image and the 2nd object is fight1.image. As you can ...
0
votes
2
answers
206
views
How to transform multiple view to same location(CGPoint)
I've got multiple UIImageViews, spread across in a view.
@IBOutlet var leftIVs: [UIImageView]!
@IBOutlet var topIVs: [UIImageView]!
@IBOutlet var rightIVs: [UIImageView]!
I'm trying to create a ...
0
votes
1
answer
184
views
CPoint positioning SwiftUI
I am drawing a line with Path, and on that line I want to have a circle if I play around I can get the circle on the line of course. However I do not understand why this code does not put the circle ...
4
votes
1
answer
4k
views
Get position of navigation bar item button in Swift
I want to get position(point) of my navigation item which is a button. If I can get this point I will be able to add a guide circle on my app. But I can't get this point right.
let point = ...
4
votes
1
answer
2k
views
SwiftUI: UIkit UIbezier to SwiftUI Path
I am trying to convert UIBezierPath to SwiftUI Path
I managed to do manually, by editing the bellow code:
From:
UIBezierPath
controlPoint1: CGPoint(x: 1226.38, y: 0), controlPoint2: CGPoint(x: ...
0
votes
0
answers
33
views
Overload the assignment operator in swift [duplicate]
Thought it'd be convenient to use tuples to set CGPoint properties, but I can't seem to figure out what swift wants me to do:
infix operator = {associativity right precedence 150} // 1
extension ...
0
votes
1
answer
24
views
use 2 different UIPanGestureRecongizer on 2 different imageviews in a viewController
my code below initializes 2 different imageviews pg and tim. I have create a seperate var for the UIPanGestureRecognizer to be used for each imageview and func to move the imageview around using ...
0
votes
0
answers
21
views
how to access the Origin XY and size Width Heigh of a container ScrollView given their Children UIViews
I the storybook, there is a main UIViewController of type ScrollView, it includes several UIViews. In the code I have an NSArray that contains all the UIViews that are withinvthe scrollView.
for some ...
0
votes
1
answer
161
views
Change line width with uislider in a subclass value
My code is trying to use a slide value to change the width of a line. Right now It is not working. I only want dont want lines drawn before the value is change to be effected only new lines after the ...