Animating strings fading in/out in Swift
I'm new to programming - but I've made strides learning Swift for iOS in the last two months. I'm making a simple typing game - and the way I've structured my project is that I have a hidden UITextView that detects the character pressed by the player, and I match that character string with a visible UITextView's character string.
What I'm looking to do now is to add some sort of animation - I'd like the individual letters to fade in/out
I've created an attributed string, added it to a UITextView, and I just can't figure out a way to animate a specific range in the string. I've tried using something along the lines of this:
UIView.animateWithDuration(1, delay: 0.5, options: .CurveEaseOut, animations: {
self.stringForPlayer.addAttribute(
NSForegroundColorAttributeName,
value: UIColor.greenColor(),
range: NSRange(location: self.rangeOfText, length: 1))
self.textViewForPlayer.attributedText = self.textForPlayer
}, completion: { finished in
println("FINISHED")}
)
with no luck. I figure maybe UIView animations are only on the view object itself and can't be used on the attributed string. Any ideas or even workarounds to make this happen? Any help is appreciated, thanks a lot!
ios string animation swift
|
show 3 more comments
I'm new to programming - but I've made strides learning Swift for iOS in the last two months. I'm making a simple typing game - and the way I've structured my project is that I have a hidden UITextView that detects the character pressed by the player, and I match that character string with a visible UITextView's character string.
What I'm looking to do now is to add some sort of animation - I'd like the individual letters to fade in/out
I've created an attributed string, added it to a UITextView, and I just can't figure out a way to animate a specific range in the string. I've tried using something along the lines of this:
UIView.animateWithDuration(1, delay: 0.5, options: .CurveEaseOut, animations: {
self.stringForPlayer.addAttribute(
NSForegroundColorAttributeName,
value: UIColor.greenColor(),
range: NSRange(location: self.rangeOfText, length: 1))
self.textViewForPlayer.attributedText = self.textForPlayer
}, completion: { finished in
println("FINISHED")}
)
with no luck. I figure maybe UIView animations are only on the view object itself and can't be used on the attributed string. Any ideas or even workarounds to make this happen? Any help is appreciated, thanks a lot!
ios string animation swift
You could try to mask the string with a UIView object, then change its alpha with animation.
– Dino Tw
Jan 30 '15 at 22:14
@DinoTw thanks for the reply. Could you elaborate a bit on how I'd mask the string? Sorry I'm quite new at this. You're saying I could create a new UIView object, and position it on top of the UITextView, and animate that instead right?
– Chris
Jan 30 '15 at 22:41
yes, you are right.
– Dino Tw
Jan 30 '15 at 22:47
Or just usetransitionWithView
instead ofanimateWithDuration
and no extra view is needed.
– Rob
Jan 30 '15 at 23:01
Thanks!transitionWithView
works for the color. I put that in the example because I couldn't figure out how to scale the size of a character in the string - so i put the closest example i could think of which was the color. Could you suggest how I'd go about making the letters "pop" (scale up and back down) as well?
– Chris
Jan 30 '15 at 23:12
|
show 3 more comments
I'm new to programming - but I've made strides learning Swift for iOS in the last two months. I'm making a simple typing game - and the way I've structured my project is that I have a hidden UITextView that detects the character pressed by the player, and I match that character string with a visible UITextView's character string.
What I'm looking to do now is to add some sort of animation - I'd like the individual letters to fade in/out
I've created an attributed string, added it to a UITextView, and I just can't figure out a way to animate a specific range in the string. I've tried using something along the lines of this:
UIView.animateWithDuration(1, delay: 0.5, options: .CurveEaseOut, animations: {
self.stringForPlayer.addAttribute(
NSForegroundColorAttributeName,
value: UIColor.greenColor(),
range: NSRange(location: self.rangeOfText, length: 1))
self.textViewForPlayer.attributedText = self.textForPlayer
}, completion: { finished in
println("FINISHED")}
)
with no luck. I figure maybe UIView animations are only on the view object itself and can't be used on the attributed string. Any ideas or even workarounds to make this happen? Any help is appreciated, thanks a lot!
ios string animation swift
I'm new to programming - but I've made strides learning Swift for iOS in the last two months. I'm making a simple typing game - and the way I've structured my project is that I have a hidden UITextView that detects the character pressed by the player, and I match that character string with a visible UITextView's character string.
What I'm looking to do now is to add some sort of animation - I'd like the individual letters to fade in/out
I've created an attributed string, added it to a UITextView, and I just can't figure out a way to animate a specific range in the string. I've tried using something along the lines of this:
UIView.animateWithDuration(1, delay: 0.5, options: .CurveEaseOut, animations: {
self.stringForPlayer.addAttribute(
NSForegroundColorAttributeName,
value: UIColor.greenColor(),
range: NSRange(location: self.rangeOfText, length: 1))
self.textViewForPlayer.attributedText = self.textForPlayer
}, completion: { finished in
println("FINISHED")}
)
with no luck. I figure maybe UIView animations are only on the view object itself and can't be used on the attributed string. Any ideas or even workarounds to make this happen? Any help is appreciated, thanks a lot!
ios string animation swift
ios string animation swift
edited Jan 30 '15 at 23:46
Chris
asked Jan 30 '15 at 21:54
ChrisChris
136319
136319
You could try to mask the string with a UIView object, then change its alpha with animation.
– Dino Tw
Jan 30 '15 at 22:14
@DinoTw thanks for the reply. Could you elaborate a bit on how I'd mask the string? Sorry I'm quite new at this. You're saying I could create a new UIView object, and position it on top of the UITextView, and animate that instead right?
– Chris
Jan 30 '15 at 22:41
yes, you are right.
– Dino Tw
Jan 30 '15 at 22:47
Or just usetransitionWithView
instead ofanimateWithDuration
and no extra view is needed.
– Rob
Jan 30 '15 at 23:01
Thanks!transitionWithView
works for the color. I put that in the example because I couldn't figure out how to scale the size of a character in the string - so i put the closest example i could think of which was the color. Could you suggest how I'd go about making the letters "pop" (scale up and back down) as well?
– Chris
Jan 30 '15 at 23:12
|
show 3 more comments
You could try to mask the string with a UIView object, then change its alpha with animation.
– Dino Tw
Jan 30 '15 at 22:14
@DinoTw thanks for the reply. Could you elaborate a bit on how I'd mask the string? Sorry I'm quite new at this. You're saying I could create a new UIView object, and position it on top of the UITextView, and animate that instead right?
– Chris
Jan 30 '15 at 22:41
yes, you are right.
– Dino Tw
Jan 30 '15 at 22:47
Or just usetransitionWithView
instead ofanimateWithDuration
and no extra view is needed.
– Rob
Jan 30 '15 at 23:01
Thanks!transitionWithView
works for the color. I put that in the example because I couldn't figure out how to scale the size of a character in the string - so i put the closest example i could think of which was the color. Could you suggest how I'd go about making the letters "pop" (scale up and back down) as well?
– Chris
Jan 30 '15 at 23:12
You could try to mask the string with a UIView object, then change its alpha with animation.
– Dino Tw
Jan 30 '15 at 22:14
You could try to mask the string with a UIView object, then change its alpha with animation.
– Dino Tw
Jan 30 '15 at 22:14
@DinoTw thanks for the reply. Could you elaborate a bit on how I'd mask the string? Sorry I'm quite new at this. You're saying I could create a new UIView object, and position it on top of the UITextView, and animate that instead right?
– Chris
Jan 30 '15 at 22:41
@DinoTw thanks for the reply. Could you elaborate a bit on how I'd mask the string? Sorry I'm quite new at this. You're saying I could create a new UIView object, and position it on top of the UITextView, and animate that instead right?
– Chris
Jan 30 '15 at 22:41
yes, you are right.
– Dino Tw
Jan 30 '15 at 22:47
yes, you are right.
– Dino Tw
Jan 30 '15 at 22:47
Or just use
transitionWithView
instead of animateWithDuration
and no extra view is needed.– Rob
Jan 30 '15 at 23:01
Or just use
transitionWithView
instead of animateWithDuration
and no extra view is needed.– Rob
Jan 30 '15 at 23:01
Thanks!
transitionWithView
works for the color. I put that in the example because I couldn't figure out how to scale the size of a character in the string - so i put the closest example i could think of which was the color. Could you suggest how I'd go about making the letters "pop" (scale up and back down) as well?– Chris
Jan 30 '15 at 23:12
Thanks!
transitionWithView
works for the color. I put that in the example because I couldn't figure out how to scale the size of a character in the string - so i put the closest example i could think of which was the color. Could you suggest how I'd go about making the letters "pop" (scale up and back down) as well?– Chris
Jan 30 '15 at 23:12
|
show 3 more comments
1 Answer
1
active
oldest
votes
You can use transition(with:...)
to do an animation. In this case, fading the word ipsum
into green. E.g. in Swift 3 and later:
let range = (playerTextView.text as NSString).range(of: "ipsum")
let string = playerTextView.attributedText.mutableCopy() as! NSMutableAttributedString
string.addAttribute(.foregroundColor, value: UIColor.green, range: range)
UIView.transition(with: playerTextView, duration: 1.0, options: .transitionCrossDissolve, animations: {
self.playerTextView.attributedText = string
})
To have the text shrink and grow during this animation is a whole different ball of wax because simple attempts to change the size of the text will cause the rest of the text view to be re laid out, which I am sure is not your intent.
In that case, I might take a snapshot of that portion of the text view, lay that snapshot over the text view, animate the resizing and transformation. And all of that assumes that what you're transforming it to at the end of the animation is exactly the same size as it was before (otherwise you have a complicated question of what to do with the rest of the text during the animation).
This is going to be a lot of work to achieve a particular animation. I'd ask whether you could accomplish the desired effect more simply other ways (e.g. nested animations, one that fades the text color to clear and then fade it to the new color making it achieve a bit of the "disappear and reappear" feel). That makes the transformation more notable while not getting lost in a rats nest of animation code.
If you wanted to fade it to clear
before fading it to the desired color (making it "pop" a little more), you could use the completion
block:
let range = (playerTextView.text as NSString).range(of: "ipsum")
let string = playerTextView.attributedText.mutableCopy() as! NSMutableAttributedString
string.addAttribute(.foregroundColor, value: UIColor.clear, range: range)
UIView.transition(with: playerTextView, duration: 0.25, options: .transitionCrossDissolve, animations: {
self.playerTextView.attributedText = string
}, completion: { _ in
string.addAttribute(.foregroundColor, value: UIColor.green, range: range)
UIView.transition(with: self.playerTextView, duration: 0.25, options: .transitionCrossDissolve, animations: {
self.playerTextView.attributedText = string
})
})
For previous versions of Swift, see prior revision of this answer.
great! Could you post an answer of how to animate the size of the characters to make them scale up and back down? (a popping animation)
– Chris
Jan 30 '15 at 23:26
just elaborating on the solution - is there a way to ensure that each run of the animation block is completed before the next one begins? These animations are triggered quickly in succession.
– Chris
Feb 2 '15 at 22:46
Increase the duration of each if you want. And make sure the second one is inside the completion block of the first, as shown above.
– Rob
Feb 2 '15 at 23:36
sorry what i meant was - what if I wanted the whole animation to finish before the next time both these blocks are called? As in, both these blocks are in a function, and the function is called quickly in succession. The second call always interrupts the first resulting in an instant completion of the first call's animations. Thanks in advance
– Chris
Feb 3 '15 at 0:13
The easy solution is to continue putting subsequenttransitionWithView
calls inside the prior one's completion block. A more complicated solution would entail wrapping your animation in aNSOperation
subclass like this answer (except usetransitionWithView
instead ofanimateWithDuration
).
– Rob
Feb 3 '15 at 4:36
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%2f28245285%2fanimating-strings-fading-in-out-in-swift%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
You can use transition(with:...)
to do an animation. In this case, fading the word ipsum
into green. E.g. in Swift 3 and later:
let range = (playerTextView.text as NSString).range(of: "ipsum")
let string = playerTextView.attributedText.mutableCopy() as! NSMutableAttributedString
string.addAttribute(.foregroundColor, value: UIColor.green, range: range)
UIView.transition(with: playerTextView, duration: 1.0, options: .transitionCrossDissolve, animations: {
self.playerTextView.attributedText = string
})
To have the text shrink and grow during this animation is a whole different ball of wax because simple attempts to change the size of the text will cause the rest of the text view to be re laid out, which I am sure is not your intent.
In that case, I might take a snapshot of that portion of the text view, lay that snapshot over the text view, animate the resizing and transformation. And all of that assumes that what you're transforming it to at the end of the animation is exactly the same size as it was before (otherwise you have a complicated question of what to do with the rest of the text during the animation).
This is going to be a lot of work to achieve a particular animation. I'd ask whether you could accomplish the desired effect more simply other ways (e.g. nested animations, one that fades the text color to clear and then fade it to the new color making it achieve a bit of the "disappear and reappear" feel). That makes the transformation more notable while not getting lost in a rats nest of animation code.
If you wanted to fade it to clear
before fading it to the desired color (making it "pop" a little more), you could use the completion
block:
let range = (playerTextView.text as NSString).range(of: "ipsum")
let string = playerTextView.attributedText.mutableCopy() as! NSMutableAttributedString
string.addAttribute(.foregroundColor, value: UIColor.clear, range: range)
UIView.transition(with: playerTextView, duration: 0.25, options: .transitionCrossDissolve, animations: {
self.playerTextView.attributedText = string
}, completion: { _ in
string.addAttribute(.foregroundColor, value: UIColor.green, range: range)
UIView.transition(with: self.playerTextView, duration: 0.25, options: .transitionCrossDissolve, animations: {
self.playerTextView.attributedText = string
})
})
For previous versions of Swift, see prior revision of this answer.
great! Could you post an answer of how to animate the size of the characters to make them scale up and back down? (a popping animation)
– Chris
Jan 30 '15 at 23:26
just elaborating on the solution - is there a way to ensure that each run of the animation block is completed before the next one begins? These animations are triggered quickly in succession.
– Chris
Feb 2 '15 at 22:46
Increase the duration of each if you want. And make sure the second one is inside the completion block of the first, as shown above.
– Rob
Feb 2 '15 at 23:36
sorry what i meant was - what if I wanted the whole animation to finish before the next time both these blocks are called? As in, both these blocks are in a function, and the function is called quickly in succession. The second call always interrupts the first resulting in an instant completion of the first call's animations. Thanks in advance
– Chris
Feb 3 '15 at 0:13
The easy solution is to continue putting subsequenttransitionWithView
calls inside the prior one's completion block. A more complicated solution would entail wrapping your animation in aNSOperation
subclass like this answer (except usetransitionWithView
instead ofanimateWithDuration
).
– Rob
Feb 3 '15 at 4:36
add a comment |
You can use transition(with:...)
to do an animation. In this case, fading the word ipsum
into green. E.g. in Swift 3 and later:
let range = (playerTextView.text as NSString).range(of: "ipsum")
let string = playerTextView.attributedText.mutableCopy() as! NSMutableAttributedString
string.addAttribute(.foregroundColor, value: UIColor.green, range: range)
UIView.transition(with: playerTextView, duration: 1.0, options: .transitionCrossDissolve, animations: {
self.playerTextView.attributedText = string
})
To have the text shrink and grow during this animation is a whole different ball of wax because simple attempts to change the size of the text will cause the rest of the text view to be re laid out, which I am sure is not your intent.
In that case, I might take a snapshot of that portion of the text view, lay that snapshot over the text view, animate the resizing and transformation. And all of that assumes that what you're transforming it to at the end of the animation is exactly the same size as it was before (otherwise you have a complicated question of what to do with the rest of the text during the animation).
This is going to be a lot of work to achieve a particular animation. I'd ask whether you could accomplish the desired effect more simply other ways (e.g. nested animations, one that fades the text color to clear and then fade it to the new color making it achieve a bit of the "disappear and reappear" feel). That makes the transformation more notable while not getting lost in a rats nest of animation code.
If you wanted to fade it to clear
before fading it to the desired color (making it "pop" a little more), you could use the completion
block:
let range = (playerTextView.text as NSString).range(of: "ipsum")
let string = playerTextView.attributedText.mutableCopy() as! NSMutableAttributedString
string.addAttribute(.foregroundColor, value: UIColor.clear, range: range)
UIView.transition(with: playerTextView, duration: 0.25, options: .transitionCrossDissolve, animations: {
self.playerTextView.attributedText = string
}, completion: { _ in
string.addAttribute(.foregroundColor, value: UIColor.green, range: range)
UIView.transition(with: self.playerTextView, duration: 0.25, options: .transitionCrossDissolve, animations: {
self.playerTextView.attributedText = string
})
})
For previous versions of Swift, see prior revision of this answer.
great! Could you post an answer of how to animate the size of the characters to make them scale up and back down? (a popping animation)
– Chris
Jan 30 '15 at 23:26
just elaborating on the solution - is there a way to ensure that each run of the animation block is completed before the next one begins? These animations are triggered quickly in succession.
– Chris
Feb 2 '15 at 22:46
Increase the duration of each if you want. And make sure the second one is inside the completion block of the first, as shown above.
– Rob
Feb 2 '15 at 23:36
sorry what i meant was - what if I wanted the whole animation to finish before the next time both these blocks are called? As in, both these blocks are in a function, and the function is called quickly in succession. The second call always interrupts the first resulting in an instant completion of the first call's animations. Thanks in advance
– Chris
Feb 3 '15 at 0:13
The easy solution is to continue putting subsequenttransitionWithView
calls inside the prior one's completion block. A more complicated solution would entail wrapping your animation in aNSOperation
subclass like this answer (except usetransitionWithView
instead ofanimateWithDuration
).
– Rob
Feb 3 '15 at 4:36
add a comment |
You can use transition(with:...)
to do an animation. In this case, fading the word ipsum
into green. E.g. in Swift 3 and later:
let range = (playerTextView.text as NSString).range(of: "ipsum")
let string = playerTextView.attributedText.mutableCopy() as! NSMutableAttributedString
string.addAttribute(.foregroundColor, value: UIColor.green, range: range)
UIView.transition(with: playerTextView, duration: 1.0, options: .transitionCrossDissolve, animations: {
self.playerTextView.attributedText = string
})
To have the text shrink and grow during this animation is a whole different ball of wax because simple attempts to change the size of the text will cause the rest of the text view to be re laid out, which I am sure is not your intent.
In that case, I might take a snapshot of that portion of the text view, lay that snapshot over the text view, animate the resizing and transformation. And all of that assumes that what you're transforming it to at the end of the animation is exactly the same size as it was before (otherwise you have a complicated question of what to do with the rest of the text during the animation).
This is going to be a lot of work to achieve a particular animation. I'd ask whether you could accomplish the desired effect more simply other ways (e.g. nested animations, one that fades the text color to clear and then fade it to the new color making it achieve a bit of the "disappear and reappear" feel). That makes the transformation more notable while not getting lost in a rats nest of animation code.
If you wanted to fade it to clear
before fading it to the desired color (making it "pop" a little more), you could use the completion
block:
let range = (playerTextView.text as NSString).range(of: "ipsum")
let string = playerTextView.attributedText.mutableCopy() as! NSMutableAttributedString
string.addAttribute(.foregroundColor, value: UIColor.clear, range: range)
UIView.transition(with: playerTextView, duration: 0.25, options: .transitionCrossDissolve, animations: {
self.playerTextView.attributedText = string
}, completion: { _ in
string.addAttribute(.foregroundColor, value: UIColor.green, range: range)
UIView.transition(with: self.playerTextView, duration: 0.25, options: .transitionCrossDissolve, animations: {
self.playerTextView.attributedText = string
})
})
For previous versions of Swift, see prior revision of this answer.
You can use transition(with:...)
to do an animation. In this case, fading the word ipsum
into green. E.g. in Swift 3 and later:
let range = (playerTextView.text as NSString).range(of: "ipsum")
let string = playerTextView.attributedText.mutableCopy() as! NSMutableAttributedString
string.addAttribute(.foregroundColor, value: UIColor.green, range: range)
UIView.transition(with: playerTextView, duration: 1.0, options: .transitionCrossDissolve, animations: {
self.playerTextView.attributedText = string
})
To have the text shrink and grow during this animation is a whole different ball of wax because simple attempts to change the size of the text will cause the rest of the text view to be re laid out, which I am sure is not your intent.
In that case, I might take a snapshot of that portion of the text view, lay that snapshot over the text view, animate the resizing and transformation. And all of that assumes that what you're transforming it to at the end of the animation is exactly the same size as it was before (otherwise you have a complicated question of what to do with the rest of the text during the animation).
This is going to be a lot of work to achieve a particular animation. I'd ask whether you could accomplish the desired effect more simply other ways (e.g. nested animations, one that fades the text color to clear and then fade it to the new color making it achieve a bit of the "disappear and reappear" feel). That makes the transformation more notable while not getting lost in a rats nest of animation code.
If you wanted to fade it to clear
before fading it to the desired color (making it "pop" a little more), you could use the completion
block:
let range = (playerTextView.text as NSString).range(of: "ipsum")
let string = playerTextView.attributedText.mutableCopy() as! NSMutableAttributedString
string.addAttribute(.foregroundColor, value: UIColor.clear, range: range)
UIView.transition(with: playerTextView, duration: 0.25, options: .transitionCrossDissolve, animations: {
self.playerTextView.attributedText = string
}, completion: { _ in
string.addAttribute(.foregroundColor, value: UIColor.green, range: range)
UIView.transition(with: self.playerTextView, duration: 0.25, options: .transitionCrossDissolve, animations: {
self.playerTextView.attributedText = string
})
})
For previous versions of Swift, see prior revision of this answer.
edited Dec 30 '18 at 17:17
answered Jan 30 '15 at 23:20
RobRob
298k49557726
298k49557726
great! Could you post an answer of how to animate the size of the characters to make them scale up and back down? (a popping animation)
– Chris
Jan 30 '15 at 23:26
just elaborating on the solution - is there a way to ensure that each run of the animation block is completed before the next one begins? These animations are triggered quickly in succession.
– Chris
Feb 2 '15 at 22:46
Increase the duration of each if you want. And make sure the second one is inside the completion block of the first, as shown above.
– Rob
Feb 2 '15 at 23:36
sorry what i meant was - what if I wanted the whole animation to finish before the next time both these blocks are called? As in, both these blocks are in a function, and the function is called quickly in succession. The second call always interrupts the first resulting in an instant completion of the first call's animations. Thanks in advance
– Chris
Feb 3 '15 at 0:13
The easy solution is to continue putting subsequenttransitionWithView
calls inside the prior one's completion block. A more complicated solution would entail wrapping your animation in aNSOperation
subclass like this answer (except usetransitionWithView
instead ofanimateWithDuration
).
– Rob
Feb 3 '15 at 4:36
add a comment |
great! Could you post an answer of how to animate the size of the characters to make them scale up and back down? (a popping animation)
– Chris
Jan 30 '15 at 23:26
just elaborating on the solution - is there a way to ensure that each run of the animation block is completed before the next one begins? These animations are triggered quickly in succession.
– Chris
Feb 2 '15 at 22:46
Increase the duration of each if you want. And make sure the second one is inside the completion block of the first, as shown above.
– Rob
Feb 2 '15 at 23:36
sorry what i meant was - what if I wanted the whole animation to finish before the next time both these blocks are called? As in, both these blocks are in a function, and the function is called quickly in succession. The second call always interrupts the first resulting in an instant completion of the first call's animations. Thanks in advance
– Chris
Feb 3 '15 at 0:13
The easy solution is to continue putting subsequenttransitionWithView
calls inside the prior one's completion block. A more complicated solution would entail wrapping your animation in aNSOperation
subclass like this answer (except usetransitionWithView
instead ofanimateWithDuration
).
– Rob
Feb 3 '15 at 4:36
great! Could you post an answer of how to animate the size of the characters to make them scale up and back down? (a popping animation)
– Chris
Jan 30 '15 at 23:26
great! Could you post an answer of how to animate the size of the characters to make them scale up and back down? (a popping animation)
– Chris
Jan 30 '15 at 23:26
just elaborating on the solution - is there a way to ensure that each run of the animation block is completed before the next one begins? These animations are triggered quickly in succession.
– Chris
Feb 2 '15 at 22:46
just elaborating on the solution - is there a way to ensure that each run of the animation block is completed before the next one begins? These animations are triggered quickly in succession.
– Chris
Feb 2 '15 at 22:46
Increase the duration of each if you want. And make sure the second one is inside the completion block of the first, as shown above.
– Rob
Feb 2 '15 at 23:36
Increase the duration of each if you want. And make sure the second one is inside the completion block of the first, as shown above.
– Rob
Feb 2 '15 at 23:36
sorry what i meant was - what if I wanted the whole animation to finish before the next time both these blocks are called? As in, both these blocks are in a function, and the function is called quickly in succession. The second call always interrupts the first resulting in an instant completion of the first call's animations. Thanks in advance
– Chris
Feb 3 '15 at 0:13
sorry what i meant was - what if I wanted the whole animation to finish before the next time both these blocks are called? As in, both these blocks are in a function, and the function is called quickly in succession. The second call always interrupts the first resulting in an instant completion of the first call's animations. Thanks in advance
– Chris
Feb 3 '15 at 0:13
The easy solution is to continue putting subsequent
transitionWithView
calls inside the prior one's completion block. A more complicated solution would entail wrapping your animation in a NSOperation
subclass like this answer (except use transitionWithView
instead of animateWithDuration
).– Rob
Feb 3 '15 at 4:36
The easy solution is to continue putting subsequent
transitionWithView
calls inside the prior one's completion block. A more complicated solution would entail wrapping your animation in a NSOperation
subclass like this answer (except use transitionWithView
instead of animateWithDuration
).– Rob
Feb 3 '15 at 4:36
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%2f28245285%2fanimating-strings-fading-in-out-in-swift%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
You could try to mask the string with a UIView object, then change its alpha with animation.
– Dino Tw
Jan 30 '15 at 22:14
@DinoTw thanks for the reply. Could you elaborate a bit on how I'd mask the string? Sorry I'm quite new at this. You're saying I could create a new UIView object, and position it on top of the UITextView, and animate that instead right?
– Chris
Jan 30 '15 at 22:41
yes, you are right.
– Dino Tw
Jan 30 '15 at 22:47
Or just use
transitionWithView
instead ofanimateWithDuration
and no extra view is needed.– Rob
Jan 30 '15 at 23:01
Thanks!
transitionWithView
works for the color. I put that in the example because I couldn't figure out how to scale the size of a character in the string - so i put the closest example i could think of which was the color. Could you suggest how I'd go about making the letters "pop" (scale up and back down) as well?– Chris
Jan 30 '15 at 23:12