trouble flipping CoreGraphics upside down arc in a UIView
I am having trouble flipping an arc using core graphics api in a UIView.
I understand that the coordinate system is different. UIkit helps me half way by transforming the coordinate system to accommodate the center I provide into a core graphic coordination system. I am assuming that when I draw an arc using core graphics api that its drawing the arc by using the core graphics coordinate system?
I can just change clockwise to false and it will give me what I need. Is this good practice?
I was playing around with CGAffineTransform’s rotation and scale, it didn’t give me what I need. Any way to flip the arc around without hawkishly changing clocking to false?
I also used UIBezierPath to draw another arc the way I want it. As I understand, UIBezierPath is a wrapper around CoreGraphics. I would like to know how I can do this using pure CoreGraphics API.
Extra question: My last function
Call path.stroke() paints the UIBezierPath path and the CGPath arcPath1. How come? 0.o
override func draw(_ rect: CGRect) {
guard let CGContext = UIGraphicsGetCurrentContext() else { return }
let boxPath = CGMutablePath()
boxPath.addLines(between:
[CGPoint(x: rect.width / 2, y: rect.height),
CGPoint(x: rect.width / 2, y: rect.height / 2),
CGPoint(x: rect.width, y: rect.height / 2)])
CGContext.beginPath() // begin new path
CGContext.addPath(boxPath.copy(strokingWithWidth: 5.0, lineCap: .square, lineJoin: .round, miterLimit: 0)) // add new path
CGContext.setFillColor(UIColor.blue.cgColor)
CGContext.fillPath()
let arcPath1 = CGMutablePath()
arcPath1.addArc(center: CGPoint(x: rect.width / 4, y: rect.height / 4 * 3),
radius: 20.0,
startAngle: CGFloat(180).degreesToRadians,
endAngle: CGFloat(360).degreesToRadians,
clockwise: true,
transform: CGAffineTransform(rotationAngle: CGFloat(0).degreesToRadians))
CGContext.beginPath()
CGContext.addPath(arcPath1)
CGContext.setStrokeColor(UIColor.blue.cgColor)
let path = UIBezierPath(arcCenter: CGPoint(x: rect.width / 4 * 3, y: rect.height / 4 * 3),
radius: 20.0,
startAngle: CGFloat(180).degreesToRadians,
endAngle: CGFloat(360).degreesToRadians,
clockwise: true)
path.lineWidth = 5.0
path.stroke()
}
Arcs, left: CG, right: Bezier
ios swift core-graphics
add a comment |
I am having trouble flipping an arc using core graphics api in a UIView.
I understand that the coordinate system is different. UIkit helps me half way by transforming the coordinate system to accommodate the center I provide into a core graphic coordination system. I am assuming that when I draw an arc using core graphics api that its drawing the arc by using the core graphics coordinate system?
I can just change clockwise to false and it will give me what I need. Is this good practice?
I was playing around with CGAffineTransform’s rotation and scale, it didn’t give me what I need. Any way to flip the arc around without hawkishly changing clocking to false?
I also used UIBezierPath to draw another arc the way I want it. As I understand, UIBezierPath is a wrapper around CoreGraphics. I would like to know how I can do this using pure CoreGraphics API.
Extra question: My last function
Call path.stroke() paints the UIBezierPath path and the CGPath arcPath1. How come? 0.o
override func draw(_ rect: CGRect) {
guard let CGContext = UIGraphicsGetCurrentContext() else { return }
let boxPath = CGMutablePath()
boxPath.addLines(between:
[CGPoint(x: rect.width / 2, y: rect.height),
CGPoint(x: rect.width / 2, y: rect.height / 2),
CGPoint(x: rect.width, y: rect.height / 2)])
CGContext.beginPath() // begin new path
CGContext.addPath(boxPath.copy(strokingWithWidth: 5.0, lineCap: .square, lineJoin: .round, miterLimit: 0)) // add new path
CGContext.setFillColor(UIColor.blue.cgColor)
CGContext.fillPath()
let arcPath1 = CGMutablePath()
arcPath1.addArc(center: CGPoint(x: rect.width / 4, y: rect.height / 4 * 3),
radius: 20.0,
startAngle: CGFloat(180).degreesToRadians,
endAngle: CGFloat(360).degreesToRadians,
clockwise: true,
transform: CGAffineTransform(rotationAngle: CGFloat(0).degreesToRadians))
CGContext.beginPath()
CGContext.addPath(arcPath1)
CGContext.setStrokeColor(UIColor.blue.cgColor)
let path = UIBezierPath(arcCenter: CGPoint(x: rect.width / 4 * 3, y: rect.height / 4 * 3),
radius: 20.0,
startAngle: CGFloat(180).degreesToRadians,
endAngle: CGFloat(360).degreesToRadians,
clockwise: true)
path.lineWidth = 5.0
path.stroke()
}
Arcs, left: CG, right: Bezier
ios swift core-graphics
1
This is a bug/feature that has existed since the first iPhone SDK. On macOS, the lower-right corner is (0, 0), but when they flipped the coordinate system on the iPhone, they didn't consider that clockwise would switch to counter-clockwise. Setting the clockwise variable "backwards" is the simplest (and therefore, probably the best) solution.
– Tim Kokesh
Nov 21 '18 at 17:18
Good to know. Thanks man.
– tensteps
Nov 21 '18 at 17:58
Ugh, typo. On macOS, (0, 0) is lower-left. The flip for iOS is vertical.
– Tim Kokesh
Dec 6 '18 at 21:25
add a comment |
I am having trouble flipping an arc using core graphics api in a UIView.
I understand that the coordinate system is different. UIkit helps me half way by transforming the coordinate system to accommodate the center I provide into a core graphic coordination system. I am assuming that when I draw an arc using core graphics api that its drawing the arc by using the core graphics coordinate system?
I can just change clockwise to false and it will give me what I need. Is this good practice?
I was playing around with CGAffineTransform’s rotation and scale, it didn’t give me what I need. Any way to flip the arc around without hawkishly changing clocking to false?
I also used UIBezierPath to draw another arc the way I want it. As I understand, UIBezierPath is a wrapper around CoreGraphics. I would like to know how I can do this using pure CoreGraphics API.
Extra question: My last function
Call path.stroke() paints the UIBezierPath path and the CGPath arcPath1. How come? 0.o
override func draw(_ rect: CGRect) {
guard let CGContext = UIGraphicsGetCurrentContext() else { return }
let boxPath = CGMutablePath()
boxPath.addLines(between:
[CGPoint(x: rect.width / 2, y: rect.height),
CGPoint(x: rect.width / 2, y: rect.height / 2),
CGPoint(x: rect.width, y: rect.height / 2)])
CGContext.beginPath() // begin new path
CGContext.addPath(boxPath.copy(strokingWithWidth: 5.0, lineCap: .square, lineJoin: .round, miterLimit: 0)) // add new path
CGContext.setFillColor(UIColor.blue.cgColor)
CGContext.fillPath()
let arcPath1 = CGMutablePath()
arcPath1.addArc(center: CGPoint(x: rect.width / 4, y: rect.height / 4 * 3),
radius: 20.0,
startAngle: CGFloat(180).degreesToRadians,
endAngle: CGFloat(360).degreesToRadians,
clockwise: true,
transform: CGAffineTransform(rotationAngle: CGFloat(0).degreesToRadians))
CGContext.beginPath()
CGContext.addPath(arcPath1)
CGContext.setStrokeColor(UIColor.blue.cgColor)
let path = UIBezierPath(arcCenter: CGPoint(x: rect.width / 4 * 3, y: rect.height / 4 * 3),
radius: 20.0,
startAngle: CGFloat(180).degreesToRadians,
endAngle: CGFloat(360).degreesToRadians,
clockwise: true)
path.lineWidth = 5.0
path.stroke()
}
Arcs, left: CG, right: Bezier
ios swift core-graphics
I am having trouble flipping an arc using core graphics api in a UIView.
I understand that the coordinate system is different. UIkit helps me half way by transforming the coordinate system to accommodate the center I provide into a core graphic coordination system. I am assuming that when I draw an arc using core graphics api that its drawing the arc by using the core graphics coordinate system?
I can just change clockwise to false and it will give me what I need. Is this good practice?
I was playing around with CGAffineTransform’s rotation and scale, it didn’t give me what I need. Any way to flip the arc around without hawkishly changing clocking to false?
I also used UIBezierPath to draw another arc the way I want it. As I understand, UIBezierPath is a wrapper around CoreGraphics. I would like to know how I can do this using pure CoreGraphics API.
Extra question: My last function
Call path.stroke() paints the UIBezierPath path and the CGPath arcPath1. How come? 0.o
override func draw(_ rect: CGRect) {
guard let CGContext = UIGraphicsGetCurrentContext() else { return }
let boxPath = CGMutablePath()
boxPath.addLines(between:
[CGPoint(x: rect.width / 2, y: rect.height),
CGPoint(x: rect.width / 2, y: rect.height / 2),
CGPoint(x: rect.width, y: rect.height / 2)])
CGContext.beginPath() // begin new path
CGContext.addPath(boxPath.copy(strokingWithWidth: 5.0, lineCap: .square, lineJoin: .round, miterLimit: 0)) // add new path
CGContext.setFillColor(UIColor.blue.cgColor)
CGContext.fillPath()
let arcPath1 = CGMutablePath()
arcPath1.addArc(center: CGPoint(x: rect.width / 4, y: rect.height / 4 * 3),
radius: 20.0,
startAngle: CGFloat(180).degreesToRadians,
endAngle: CGFloat(360).degreesToRadians,
clockwise: true,
transform: CGAffineTransform(rotationAngle: CGFloat(0).degreesToRadians))
CGContext.beginPath()
CGContext.addPath(arcPath1)
CGContext.setStrokeColor(UIColor.blue.cgColor)
let path = UIBezierPath(arcCenter: CGPoint(x: rect.width / 4 * 3, y: rect.height / 4 * 3),
radius: 20.0,
startAngle: CGFloat(180).degreesToRadians,
endAngle: CGFloat(360).degreesToRadians,
clockwise: true)
path.lineWidth = 5.0
path.stroke()
}
Arcs, left: CG, right: Bezier
ios swift core-graphics
ios swift core-graphics
edited Nov 21 '18 at 18:00
asked Nov 21 '18 at 15:09
tensteps
33
33
1
This is a bug/feature that has existed since the first iPhone SDK. On macOS, the lower-right corner is (0, 0), but when they flipped the coordinate system on the iPhone, they didn't consider that clockwise would switch to counter-clockwise. Setting the clockwise variable "backwards" is the simplest (and therefore, probably the best) solution.
– Tim Kokesh
Nov 21 '18 at 17:18
Good to know. Thanks man.
– tensteps
Nov 21 '18 at 17:58
Ugh, typo. On macOS, (0, 0) is lower-left. The flip for iOS is vertical.
– Tim Kokesh
Dec 6 '18 at 21:25
add a comment |
1
This is a bug/feature that has existed since the first iPhone SDK. On macOS, the lower-right corner is (0, 0), but when they flipped the coordinate system on the iPhone, they didn't consider that clockwise would switch to counter-clockwise. Setting the clockwise variable "backwards" is the simplest (and therefore, probably the best) solution.
– Tim Kokesh
Nov 21 '18 at 17:18
Good to know. Thanks man.
– tensteps
Nov 21 '18 at 17:58
Ugh, typo. On macOS, (0, 0) is lower-left. The flip for iOS is vertical.
– Tim Kokesh
Dec 6 '18 at 21:25
1
1
This is a bug/feature that has existed since the first iPhone SDK. On macOS, the lower-right corner is (0, 0), but when they flipped the coordinate system on the iPhone, they didn't consider that clockwise would switch to counter-clockwise. Setting the clockwise variable "backwards" is the simplest (and therefore, probably the best) solution.
– Tim Kokesh
Nov 21 '18 at 17:18
This is a bug/feature that has existed since the first iPhone SDK. On macOS, the lower-right corner is (0, 0), but when they flipped the coordinate system on the iPhone, they didn't consider that clockwise would switch to counter-clockwise. Setting the clockwise variable "backwards" is the simplest (and therefore, probably the best) solution.
– Tim Kokesh
Nov 21 '18 at 17:18
Good to know. Thanks man.
– tensteps
Nov 21 '18 at 17:58
Good to know. Thanks man.
– tensteps
Nov 21 '18 at 17:58
Ugh, typo. On macOS, (0, 0) is lower-left. The flip for iOS is vertical.
– Tim Kokesh
Dec 6 '18 at 21:25
Ugh, typo. On macOS, (0, 0) is lower-left. The flip for iOS is vertical.
– Tim Kokesh
Dec 6 '18 at 21:25
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415001%2ftrouble-flipping-coregraphics-upside-down-arc-in-a-uiview%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415001%2ftrouble-flipping-coregraphics-upside-down-arc-in-a-uiview%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
This is a bug/feature that has existed since the first iPhone SDK. On macOS, the lower-right corner is (0, 0), but when they flipped the coordinate system on the iPhone, they didn't consider that clockwise would switch to counter-clockwise. Setting the clockwise variable "backwards" is the simplest (and therefore, probably the best) solution.
– Tim Kokesh
Nov 21 '18 at 17:18
Good to know. Thanks man.
– tensteps
Nov 21 '18 at 17:58
Ugh, typo. On macOS, (0, 0) is lower-left. The flip for iOS is vertical.
– Tim Kokesh
Dec 6 '18 at 21:25