Swift iOS Background Color View animation as Timer
I am trying to have the background on my viewController start out blue. As one minute passes I want the blue to slowly go down on the screen in 60 seconds. It has finished but the screen is not white.
Here is what I have tried.
I have created a blue view and divided the screens height by 120. Using a scheduled timer every 1/2 second I lower the screen 1/120th of the way.
It works but it does not look very good. How can I animate this in a way that it would look very smooth.
ios swift uiviewanimation
add a comment |
I am trying to have the background on my viewController start out blue. As one minute passes I want the blue to slowly go down on the screen in 60 seconds. It has finished but the screen is not white.
Here is what I have tried.
I have created a blue view and divided the screens height by 120. Using a scheduled timer every 1/2 second I lower the screen 1/120th of the way.
It works but it does not look very good. How can I animate this in a way that it would look very smooth.
ios swift uiviewanimation
1
Add your code in quesiton
– Prashant Tukadiya
Jan 1 at 5:08
add a comment |
I am trying to have the background on my viewController start out blue. As one minute passes I want the blue to slowly go down on the screen in 60 seconds. It has finished but the screen is not white.
Here is what I have tried.
I have created a blue view and divided the screens height by 120. Using a scheduled timer every 1/2 second I lower the screen 1/120th of the way.
It works but it does not look very good. How can I animate this in a way that it would look very smooth.
ios swift uiviewanimation
I am trying to have the background on my viewController start out blue. As one minute passes I want the blue to slowly go down on the screen in 60 seconds. It has finished but the screen is not white.
Here is what I have tried.
I have created a blue view and divided the screens height by 120. Using a scheduled timer every 1/2 second I lower the screen 1/120th of the way.
It works but it does not look very good. How can I animate this in a way that it would look very smooth.
ios swift uiviewanimation
ios swift uiviewanimation
edited Jan 1 at 6:34


Rakesha Shastri
7,33721434
7,33721434
asked Jan 1 at 5:05
user6520705user6520705
261625
261625
1
Add your code in quesiton
– Prashant Tukadiya
Jan 1 at 5:08
add a comment |
1
Add your code in quesiton
– Prashant Tukadiya
Jan 1 at 5:08
1
1
Add your code in quesiton
– Prashant Tukadiya
Jan 1 at 5:08
Add your code in quesiton
– Prashant Tukadiya
Jan 1 at 5:08
add a comment |
1 Answer
1
active
oldest
votes
Why would you need to use timer for that ? Just use the animate block.
UIView.animate(withDuration: 60, delay: 0, options: [.allowUserInteraction], animations: {
// If you are not using autolayout, just animate the frame.
topAnchorConstraint.constant = -view.frame.height // Or any horizontal anchor
view.layoutIfNeeded()
}, completion: nil)
Since this animation is over 60 seconds, I'm assuming you need user interaction during animation which you can set it in the options
parameter.
P.S: You would need another view below this one with a white color to actually reveal a white view below it.
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%2f53993119%2fswift-ios-background-color-view-animation-as-timer%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
Why would you need to use timer for that ? Just use the animate block.
UIView.animate(withDuration: 60, delay: 0, options: [.allowUserInteraction], animations: {
// If you are not using autolayout, just animate the frame.
topAnchorConstraint.constant = -view.frame.height // Or any horizontal anchor
view.layoutIfNeeded()
}, completion: nil)
Since this animation is over 60 seconds, I'm assuming you need user interaction during animation which you can set it in the options
parameter.
P.S: You would need another view below this one with a white color to actually reveal a white view below it.
add a comment |
Why would you need to use timer for that ? Just use the animate block.
UIView.animate(withDuration: 60, delay: 0, options: [.allowUserInteraction], animations: {
// If you are not using autolayout, just animate the frame.
topAnchorConstraint.constant = -view.frame.height // Or any horizontal anchor
view.layoutIfNeeded()
}, completion: nil)
Since this animation is over 60 seconds, I'm assuming you need user interaction during animation which you can set it in the options
parameter.
P.S: You would need another view below this one with a white color to actually reveal a white view below it.
add a comment |
Why would you need to use timer for that ? Just use the animate block.
UIView.animate(withDuration: 60, delay: 0, options: [.allowUserInteraction], animations: {
// If you are not using autolayout, just animate the frame.
topAnchorConstraint.constant = -view.frame.height // Or any horizontal anchor
view.layoutIfNeeded()
}, completion: nil)
Since this animation is over 60 seconds, I'm assuming you need user interaction during animation which you can set it in the options
parameter.
P.S: You would need another view below this one with a white color to actually reveal a white view below it.
Why would you need to use timer for that ? Just use the animate block.
UIView.animate(withDuration: 60, delay: 0, options: [.allowUserInteraction], animations: {
// If you are not using autolayout, just animate the frame.
topAnchorConstraint.constant = -view.frame.height // Or any horizontal anchor
view.layoutIfNeeded()
}, completion: nil)
Since this animation is over 60 seconds, I'm assuming you need user interaction during animation which you can set it in the options
parameter.
P.S: You would need another view below this one with a white color to actually reveal a white view below it.
edited Jan 1 at 6:33


andesta.erfan
5421323
5421323
answered Jan 1 at 5:19


Rakesha ShastriRakesha Shastri
7,33721434
7,33721434
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%2f53993119%2fswift-ios-background-color-view-animation-as-timer%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
Add your code in quesiton
– Prashant Tukadiya
Jan 1 at 5:08