After making an animation on a UITextField, if I tap on my UITextField, it disappears. Why does this happen and how can I fix it? I'm not sure how to search for this online. Here's my animation code that I'm doing in viewDidAppear
UIView.animateWithDuration(1.0, delay: 0.0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.0, options: [], animations: {
self.userName.center.x += self.view.bounds.width
self.userName.alpha = 1.0
}, completion: nil)
Before this I set the UITextField to be off the screen. So what my animation is supposed to do is start from outside of the screen and animate it to be visibly in the center of the screen. Don't know if that makes a difference in this question though.
The animation works great, it's just that when I try to tap on the UITextField to enter a username, the entire UITextField just disappears and I'm left with just a keyboard. I'm sure it's something simple I'm missing. Can someone lead me in the right direction?
Related
Im trying to make an animation over a view in my ViewController.
My problem is that the scroll/swipe gestures over other elements like UITableViewControllers or UIPageViewControllers get disabled until the animation finishes.
How can I avoid this behaviour?
Do your animations using allowUserInteraction option:
UIView.animate(withDuration: duration, delay: 0, options: .allowUserInteraction,
animations: {
// Your animations here
},
completion: nil
)
I'm trying to animate a label moving to another place with a spring effect.
UIView.animateWithDuration(1, delay: 1, usingSpringWithDamping: 0.9, initialSpringVelocity: 0, options: [], animations: { () -> Void in
self.textLabel.center = CGPointMake(self.view.center.x, self.view.center.y-220)
}, completion: { (Bool) -> Void in
})
Basically it animates the label moving to a wrong place but after the animation finishes it suddenly jumps to the place I want it to go to.
What is causing this issue?
I had an animation inside another animation and it caused this issue. Now it is solved.
How do you animate only the contents of a UIImageView? If the image view is centered in the middle of the screen how do you animate the image to slide in from the left but only be shown within the frame of the image view?
As if you are looking at a wall with a window and someone walks by. You don't see them until they are in the frame of the window.
The code below certainly does not do it. I had it a few days ago with ease and erased it and now I can't remember how I did it. It was pretty simple but now it's driving me crazy.
self.lockImages[button.tag].center.x -= self.lockImages[button.tag].bounds.width
UIView.animateWithDuration(2.0, delay: 0.0, usingSpringWithDamping: 0.5, initialSpringVelocity: 1.0, options: nil, animations: { () -> Void in
self.lockImages[button.tag].center.x += self.lockImages[button.tag].bounds.maxX
}, completion: { (Bool) -> Void in
})
UIImageView a subclass of UIView, inherits the .clipsToBounds() method, which will create the desired effect.
I am making a Karaoke app that a user needs to be able to start-over by pressing a button.
I have a UIScrollView that contains a large block of text in a UITextView.
I am using UIView.animateWithDuration to scroll the text for a certain duration. I need to be able to interrupt/stop the animation and reset it back to the beginning.
Unfortunately, for me, whenever I stop the animation, the UITextView disappears and I can't seem to re-add it.
let bottomOffset:CGPoint = CGPoint(x: 0, y: self.textView.frame.size.height)
UIView.animateWithDuration(NSTimeInterval(duration),
delay: NSTimeInterval(0.0) ,
options: UIViewAnimationOptions.CurveLinear,
animations: {
self.scrollView.setContentOffset(bottomOffset, animated: false)
},
completion: { finished in
reset()
}
)
I am stopping the animation by calling:
UIView.animateWithDuration(0.0, animations: {
self.scrollView.scrollRectToVisible(CGRect(x: 0, y: 0, width: 0, height: 0), animated: true)
})
I need to figure out how to:
Stop the animation
Keep the UITextView visible
Scroll the UIScrollView back to the top
Start scrolling again
My codebase is in Swift, but I will gladly accept answers in Objective-C.
I'm making a login screen in iOS 8 using Storyboard (Xcode6 beta7). Here's an image of the basic idea:
Pressing inside any of the textfields brings up the keyboard, and pressing outside any of them dismisses it again using:
self.view.endEditing(true)
So pressing the login button makes the keyboard disappear.
When the user enters invalid login credentials I want the dialog view to increase in height and show some error message:
I'm doing this with an animation using the following function:
func increaseHeight(view: UIView, increment: CGFloat) {
UIView.animateWithDuration(1.0,
delay: 0.0,
usingSpringWithDamping: 0.3,
initialSpringVelocity: 3.0,
options: UIViewAnimationOptions.CurveEaseInOut,
animations: ({
view.frame = CGRect(
x: view.frame.origin.x,
y: view.frame.origin.y,
width: view.frame.width,
height: view.frame.height + increment
)
}),
completion: nil
)
}
If I invoke this function, let's say by pressing the login button, it's all working as I want. The animation is performed and the error message is shown.
To the the problem
However, if I first start to edit any of the textfields (i.e. bringing the keyboard up) and then press the login button, the animation is performed – but it bounces back to its original height.
How can I make the height increment persist after the keyboard has been dismissed?
If you are using auto-layout you need to change constraints not frame of the view.
heightOfViewConstraint.constant += increment
UIView animation....{
self.layoutIfNeeded()
}
This should keep your view stretched, but only if you are using auto-layout and constraints.