Change subview layer position
Good evening,
I have been trying to figure out how to fade a screen when I press a button in order to give a subview a more distinct appearance. I have researched zPositions and I thought that implementing this feature within my code would help. When I run my code, the entire screen fades. I would like there to be a circle progress ring that shows up, while the background is faded. I will show a picture and my code. Thank you in advance.
@objc func handlePost() {
let center = view.center
let trackLayer = CAShapeLayer()
let circularPath = UIBezierPath(arcCenter: center, radius: 100, startAngle: -CGFloat.pi / 2, endAngle: 2 * CGFloat.pi, clockwise: true)
blackScreen=UIView(frame: self.view.bounds)
blackScreen.backgroundColor=UIColor(white: 0, alpha: 0.8)
blackScreen.isHidden=true
self.navigationController?.view.addSubview(blackScreen)
blackScreen.layer.zPosition=50
blackScreen.isHidden=false
self.view.backgroundColor = UIColor.white
trackLayer.path = circularPath.cgPath
trackLayer.strokeColor = UIColor.lightGray.cgColor
trackLayer.lineWidth = 10
trackLayer.fillColor = UIColor.clear.cgColor
trackLayer.lineCap = kCALineCapRound
// The zPosition is supposed to bring this layer to the front.
trackLayer.zPosition = 100
shapeLayer.path = circularPath.cgPath
shapeLayer.strokeColor = GREEN_Theme.cgColor
shapeLayer.lineWidth = 10
shapeLayer.fillColor = UIColor.clear.cgColor
shapeLayer.lineCap = kCALineCapRound
shapeLayer.strokeEnd = 0
// The zPosition is supposed to bring this layer to the front.
shapeLayer.zPosition = 100
let basicAnimation = CABasicAnimation(keyPath: "strokeEnd")
basicAnimation.toValue = 1
basicAnimation.duration = 2
basicAnimation.fillMode = kCAFillModeForwards
basicAnimation.isRemovedOnCompletion = false
shapeLayer.add(basicAnimation, forKey: "dataSearch")
shapeLayer.removeAnimation(forKey: "finished")
view.layer.addSublayer(trackLayer)
view.layer.addSublayer(shapeLayer)
}
xcode uiview layer zposition
add a comment |
Good evening,
I have been trying to figure out how to fade a screen when I press a button in order to give a subview a more distinct appearance. I have researched zPositions and I thought that implementing this feature within my code would help. When I run my code, the entire screen fades. I would like there to be a circle progress ring that shows up, while the background is faded. I will show a picture and my code. Thank you in advance.
@objc func handlePost() {
let center = view.center
let trackLayer = CAShapeLayer()
let circularPath = UIBezierPath(arcCenter: center, radius: 100, startAngle: -CGFloat.pi / 2, endAngle: 2 * CGFloat.pi, clockwise: true)
blackScreen=UIView(frame: self.view.bounds)
blackScreen.backgroundColor=UIColor(white: 0, alpha: 0.8)
blackScreen.isHidden=true
self.navigationController?.view.addSubview(blackScreen)
blackScreen.layer.zPosition=50
blackScreen.isHidden=false
self.view.backgroundColor = UIColor.white
trackLayer.path = circularPath.cgPath
trackLayer.strokeColor = UIColor.lightGray.cgColor
trackLayer.lineWidth = 10
trackLayer.fillColor = UIColor.clear.cgColor
trackLayer.lineCap = kCALineCapRound
// The zPosition is supposed to bring this layer to the front.
trackLayer.zPosition = 100
shapeLayer.path = circularPath.cgPath
shapeLayer.strokeColor = GREEN_Theme.cgColor
shapeLayer.lineWidth = 10
shapeLayer.fillColor = UIColor.clear.cgColor
shapeLayer.lineCap = kCALineCapRound
shapeLayer.strokeEnd = 0
// The zPosition is supposed to bring this layer to the front.
shapeLayer.zPosition = 100
let basicAnimation = CABasicAnimation(keyPath: "strokeEnd")
basicAnimation.toValue = 1
basicAnimation.duration = 2
basicAnimation.fillMode = kCAFillModeForwards
basicAnimation.isRemovedOnCompletion = false
shapeLayer.add(basicAnimation, forKey: "dataSearch")
shapeLayer.removeAnimation(forKey: "finished")
view.layer.addSublayer(trackLayer)
view.layer.addSublayer(shapeLayer)
}
xcode uiview layer zposition
This just a duplicate of your stackoverflow.com/questions/53386470/…. Don’t do that.
– matt
Nov 20 '18 at 19:51
@matt this is not a duplicate. They are two different questions. The first question was asking how to fade the screen, this question is asking how to bring a layer above the fade. Thank you for you concern though!
– zach wilcox
Nov 20 '18 at 19:53
@matt I did see how they go hand in hand, so I deleted the previous post and decided to keep this one. Because it does answer the previous question, and now it is asking a new one
– zach wilcox
Nov 20 '18 at 20:07
@matt I did that by using zPosition, but when I run the app it still shows behind. I’ve cleaned build history and re ran it and it still shows this way.
– zach wilcox
Nov 20 '18 at 23:02
add a comment |
Good evening,
I have been trying to figure out how to fade a screen when I press a button in order to give a subview a more distinct appearance. I have researched zPositions and I thought that implementing this feature within my code would help. When I run my code, the entire screen fades. I would like there to be a circle progress ring that shows up, while the background is faded. I will show a picture and my code. Thank you in advance.
@objc func handlePost() {
let center = view.center
let trackLayer = CAShapeLayer()
let circularPath = UIBezierPath(arcCenter: center, radius: 100, startAngle: -CGFloat.pi / 2, endAngle: 2 * CGFloat.pi, clockwise: true)
blackScreen=UIView(frame: self.view.bounds)
blackScreen.backgroundColor=UIColor(white: 0, alpha: 0.8)
blackScreen.isHidden=true
self.navigationController?.view.addSubview(blackScreen)
blackScreen.layer.zPosition=50
blackScreen.isHidden=false
self.view.backgroundColor = UIColor.white
trackLayer.path = circularPath.cgPath
trackLayer.strokeColor = UIColor.lightGray.cgColor
trackLayer.lineWidth = 10
trackLayer.fillColor = UIColor.clear.cgColor
trackLayer.lineCap = kCALineCapRound
// The zPosition is supposed to bring this layer to the front.
trackLayer.zPosition = 100
shapeLayer.path = circularPath.cgPath
shapeLayer.strokeColor = GREEN_Theme.cgColor
shapeLayer.lineWidth = 10
shapeLayer.fillColor = UIColor.clear.cgColor
shapeLayer.lineCap = kCALineCapRound
shapeLayer.strokeEnd = 0
// The zPosition is supposed to bring this layer to the front.
shapeLayer.zPosition = 100
let basicAnimation = CABasicAnimation(keyPath: "strokeEnd")
basicAnimation.toValue = 1
basicAnimation.duration = 2
basicAnimation.fillMode = kCAFillModeForwards
basicAnimation.isRemovedOnCompletion = false
shapeLayer.add(basicAnimation, forKey: "dataSearch")
shapeLayer.removeAnimation(forKey: "finished")
view.layer.addSublayer(trackLayer)
view.layer.addSublayer(shapeLayer)
}
xcode uiview layer zposition
Good evening,
I have been trying to figure out how to fade a screen when I press a button in order to give a subview a more distinct appearance. I have researched zPositions and I thought that implementing this feature within my code would help. When I run my code, the entire screen fades. I would like there to be a circle progress ring that shows up, while the background is faded. I will show a picture and my code. Thank you in advance.
@objc func handlePost() {
let center = view.center
let trackLayer = CAShapeLayer()
let circularPath = UIBezierPath(arcCenter: center, radius: 100, startAngle: -CGFloat.pi / 2, endAngle: 2 * CGFloat.pi, clockwise: true)
blackScreen=UIView(frame: self.view.bounds)
blackScreen.backgroundColor=UIColor(white: 0, alpha: 0.8)
blackScreen.isHidden=true
self.navigationController?.view.addSubview(blackScreen)
blackScreen.layer.zPosition=50
blackScreen.isHidden=false
self.view.backgroundColor = UIColor.white
trackLayer.path = circularPath.cgPath
trackLayer.strokeColor = UIColor.lightGray.cgColor
trackLayer.lineWidth = 10
trackLayer.fillColor = UIColor.clear.cgColor
trackLayer.lineCap = kCALineCapRound
// The zPosition is supposed to bring this layer to the front.
trackLayer.zPosition = 100
shapeLayer.path = circularPath.cgPath
shapeLayer.strokeColor = GREEN_Theme.cgColor
shapeLayer.lineWidth = 10
shapeLayer.fillColor = UIColor.clear.cgColor
shapeLayer.lineCap = kCALineCapRound
shapeLayer.strokeEnd = 0
// The zPosition is supposed to bring this layer to the front.
shapeLayer.zPosition = 100
let basicAnimation = CABasicAnimation(keyPath: "strokeEnd")
basicAnimation.toValue = 1
basicAnimation.duration = 2
basicAnimation.fillMode = kCAFillModeForwards
basicAnimation.isRemovedOnCompletion = false
shapeLayer.add(basicAnimation, forKey: "dataSearch")
shapeLayer.removeAnimation(forKey: "finished")
view.layer.addSublayer(trackLayer)
view.layer.addSublayer(shapeLayer)
}
xcode uiview layer zposition
xcode uiview layer zposition
asked Nov 20 '18 at 18:58


zach wilcoxzach wilcox
217
217
This just a duplicate of your stackoverflow.com/questions/53386470/…. Don’t do that.
– matt
Nov 20 '18 at 19:51
@matt this is not a duplicate. They are two different questions. The first question was asking how to fade the screen, this question is asking how to bring a layer above the fade. Thank you for you concern though!
– zach wilcox
Nov 20 '18 at 19:53
@matt I did see how they go hand in hand, so I deleted the previous post and decided to keep this one. Because it does answer the previous question, and now it is asking a new one
– zach wilcox
Nov 20 '18 at 20:07
@matt I did that by using zPosition, but when I run the app it still shows behind. I’ve cleaned build history and re ran it and it still shows this way.
– zach wilcox
Nov 20 '18 at 23:02
add a comment |
This just a duplicate of your stackoverflow.com/questions/53386470/…. Don’t do that.
– matt
Nov 20 '18 at 19:51
@matt this is not a duplicate. They are two different questions. The first question was asking how to fade the screen, this question is asking how to bring a layer above the fade. Thank you for you concern though!
– zach wilcox
Nov 20 '18 at 19:53
@matt I did see how they go hand in hand, so I deleted the previous post and decided to keep this one. Because it does answer the previous question, and now it is asking a new one
– zach wilcox
Nov 20 '18 at 20:07
@matt I did that by using zPosition, but when I run the app it still shows behind. I’ve cleaned build history and re ran it and it still shows this way.
– zach wilcox
Nov 20 '18 at 23:02
This just a duplicate of your stackoverflow.com/questions/53386470/…. Don’t do that.
– matt
Nov 20 '18 at 19:51
This just a duplicate of your stackoverflow.com/questions/53386470/…. Don’t do that.
– matt
Nov 20 '18 at 19:51
@matt this is not a duplicate. They are two different questions. The first question was asking how to fade the screen, this question is asking how to bring a layer above the fade. Thank you for you concern though!
– zach wilcox
Nov 20 '18 at 19:53
@matt this is not a duplicate. They are two different questions. The first question was asking how to fade the screen, this question is asking how to bring a layer above the fade. Thank you for you concern though!
– zach wilcox
Nov 20 '18 at 19:53
@matt I did see how they go hand in hand, so I deleted the previous post and decided to keep this one. Because it does answer the previous question, and now it is asking a new one
– zach wilcox
Nov 20 '18 at 20:07
@matt I did see how they go hand in hand, so I deleted the previous post and decided to keep this one. Because it does answer the previous question, and now it is asking a new one
– zach wilcox
Nov 20 '18 at 20:07
@matt I did that by using zPosition, but when I run the app it still shows behind. I’ve cleaned build history and re ran it and it still shows this way.
– zach wilcox
Nov 20 '18 at 23:02
@matt I did that by using zPosition, but when I run the app it still shows behind. I’ve cleaned build history and re ran it and it still shows this way.
– zach wilcox
Nov 20 '18 at 23:02
add a comment |
1 Answer
1
active
oldest
votes
Again after spending hours with my code, I managed to figure out my own answer.
before I had
self.navigationController?.view.addSubview(blackScreen)
// (faded screen)
I simply needed to add
self.view.addSubview(blackScreen)
to turn it into a layer that way I could manipulate it with my zPosition.
add a comment |
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%2f53399774%2fchange-subview-layer-position%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Again after spending hours with my code, I managed to figure out my own answer.
before I had
self.navigationController?.view.addSubview(blackScreen)
// (faded screen)
I simply needed to add
self.view.addSubview(blackScreen)
to turn it into a layer that way I could manipulate it with my zPosition.
add a comment |
Again after spending hours with my code, I managed to figure out my own answer.
before I had
self.navigationController?.view.addSubview(blackScreen)
// (faded screen)
I simply needed to add
self.view.addSubview(blackScreen)
to turn it into a layer that way I could manipulate it with my zPosition.
add a comment |
Again after spending hours with my code, I managed to figure out my own answer.
before I had
self.navigationController?.view.addSubview(blackScreen)
// (faded screen)
I simply needed to add
self.view.addSubview(blackScreen)
to turn it into a layer that way I could manipulate it with my zPosition.
Again after spending hours with my code, I managed to figure out my own answer.
before I had
self.navigationController?.view.addSubview(blackScreen)
// (faded screen)
I simply needed to add
self.view.addSubview(blackScreen)
to turn it into a layer that way I could manipulate it with my zPosition.
answered Nov 21 '18 at 4:26


zach wilcoxzach wilcox
217
217
add a comment |
add a comment |
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.
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%2f53399774%2fchange-subview-layer-position%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
This just a duplicate of your stackoverflow.com/questions/53386470/…. Don’t do that.
– matt
Nov 20 '18 at 19:51
@matt this is not a duplicate. They are two different questions. The first question was asking how to fade the screen, this question is asking how to bring a layer above the fade. Thank you for you concern though!
– zach wilcox
Nov 20 '18 at 19:53
@matt I did see how they go hand in hand, so I deleted the previous post and decided to keep this one. Because it does answer the previous question, and now it is asking a new one
– zach wilcox
Nov 20 '18 at 20:07
@matt I did that by using zPosition, but when I run the app it still shows behind. I’ve cleaned build history and re ran it and it still shows this way.
– zach wilcox
Nov 20 '18 at 23:02