How to use the default iOS7 UIAnimation curve
Here's how I do it (at least when the keyboard is about to be shown)
- (void)keyboardWillShow:(NSNotification *)notification {
NSDictionary *keyboardAnimationDetail = [notification userInfo];
UIViewAnimationCurve animationCurve = [keyboardAnimationDetail[UIKeyboardAnimationCurveUserInfoKey] integerValue];
CGFloat duration = [keyboardAnimationDetail[UIKeyboardAnimationDurationUserInfoKey] floatValue];
[UIView animateWithDuration:duration delay:0.0 options:(animationCurve << 16) animations:^{
// Set the new properties to be animated here
} completion:nil];
}
You get the animation curve from the keyboard notification as usual and translate it to an animation option by bit-shifting it.
iOS 7 - Keyboard animation
Now I found the solution. The animation starts from the point {0, 920}
to {0, 352}
. The problem was that the UITableView
object started with a size of {160, 568}
, so I changed the size of the UITableView
to {160, 920}
before the animation was started.
Concerning to the unknown animation curve, I just set the parameter to animationCurve << 16
to convert it from a view animation curve to a view animation option.
The value is not equal to the linear, ease in, ease out and ease inout animation curve.
Here is my code:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
and:
- (void)keyboardWillShow:(NSNotification *)aNotification {
NSDictionary *userInfo = aNotification.userInfo;
//
// Get keyboard size.
NSValue *beginFrameValue = userInfo[UIKeyboardFrameBeginUserInfoKey];
CGRect keyboardBeginFrame = [self.view convertRect:beginFrameValue.CGRectValue fromView:nil];
NSValue *endFrameValue = userInfo[UIKeyboardFrameEndUserInfoKey];
CGRect keyboardEndFrame = [self.view convertRect:endFrameValue.CGRectValue fromView:nil];
//
// Get keyboard animation.
NSNumber *durationValue = userInfo[UIKeyboardAnimationDurationUserInfoKey];
NSTimeInterval animationDuration = durationValue.doubleValue;
NSNumber *curveValue = userInfo[UIKeyboardAnimationCurveUserInfoKey];
UIViewAnimationCurve animationCurve = curveValue.intValue;
//
// Create animation.
CGRect tableViewFrame = self.tableView.frame;
bTableViewFrame.size.height = (keyboardBeginFrame.origin.y - tableViewFrame.origin.y);
self.tableView.frame = tableViewFrame;
void (^animations)() = ^() {
CGRect tableViewFrame = self.tableView.frame;
tableViewFrame.size.height = (keyboardEndFrame.origin.y - tableViewFrame.origin.y);
self.tableView.frame = tableViewFrame;
};
//
// Begin animation.
[UIView animateWithDuration:animationDuration
delay:0.0
options:(animationCurve << 16)
animations:animations
completion:nil];
}
What is the animation speed of the keyboard appearing in iOS8?
You can get the animation duration and the animation curve from the userInfo dictionary on the keyboardWillShow: notifications.
First register for the notification
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
Then get the values from the notifications userInfo keys.
- (void)keyboardWillShow:(NSNotification*)notification {
NSNumber *duration = [notification.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
NSNumber *curve = [notification.userInfo objectForKey: UIKeyboardAnimationCurveUserInfoKey];
// Do stuff with these values.
}
There are a lot more of these keys, and you can also get them from the UIKeyboardWillDismiss notification.
This functionality is available all the way back to iOS 3.0 :D
Heres the docs:
https://developer.apple.com/library/ios/documentation/uikit/reference/UIWindow_Class/UIWindowClassReference/UIWindowClassReference.html#//apple_ref/doc/constant_group/Keyboard_Notification_User_Info_Keys
Swift Version
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
@objc func keyboardWillShow(_ notification: Notification) {
let duration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey]
let curve = notification.userInfo?[UIResponder.keyboardAnimationCurveUserInfoKey]
}
What is the iPhone's default keyboard animation rate?
- (NSTimeInterval)keyboardAnimationDurationForNotification:(NSNotification*)notification
{
NSDictionary* info = [notification userInfo];
NSValue* value = [info objectForKey:UIKeyboardAnimationDurationUserInfoKey];
NSTimeInterval duration = 0;
[value getValue:&duration];
return duration;
}
How to animate without an ease in iOS?
Don't animate. If you want it to appear and disappear instantly, try something like this:
viewcontroller.m
@property (strong, nonatomic) NSTimer *timer;
- (void)viewDidLoad {
if (!self.timer) {
self.timer = [NSTimer scheduledTimerWithTimeInterval:0.7 target:self selector:@selector(alternate) userInfo:nil repeats:YES];
}
}
- (void)alternate {
self.myDotView.hidden = !self.myDotView.hidden;
}
- (void)viewWillDisappear {
[self.timer invalidate];
self.timer = nil;
}
Curve Animation in Swift and UIKit - Parabolic Movement from starting/endingpoint
I don't know much about scene kit, but if you have a way to make your sprite travel across a Bezier path then a quadratic (not cubic) Bezier path is exactly what you need. A parabola is a quadratic curve, so it should be easy to model with a Quadratic bezier (2 end points plus a single control point.)
Creating a quadratic bezier curve is trivially easy. you specify a start and end point and a control point, and the curve follows the V defined by those 3 points.
Swift: NSNumber is not a subtype of UIViewAnimationCurve
UIView.setAnimationCurve(UIViewAnimationCurve.fromRaw(userInfo[UIKeyboardAnimationCurveUserInfoKey].integerValue)!)
Read more: Swift enumerations & fromRaw()
UPDATE
Based on this answer to How to use the default iOS7 UIAnimation curve, I use the new block-based animation method, + animateWithDuration:delay:options:animations:completion:
, and get the UIViewAnimationOptions
like so:
let options = UIViewAnimationOptions(UInt((userInfo[UIKeyboardAnimationCurveUserInfoKey] as NSNumber).integerValue << 16))
UIView block based animation weird behavior
I've found the answer.
I tis because of the additive animations in iOS 8 and above. Here is a very useful link which explains what actually happens and why the animation freezes.
http://iosoteric.com/additive-animations-animatewithduration-in-ios-8/
Related Topics
Removing Object from Array in Swift 3
How to Resize Uitableviewcell to Fit Its Content
How to Reset the Application Data After Each Test with Xcode 7 UI Testing
Swift: Equivalent Objective-C Runtime Class
How to Retrieve Messages Logged with Os_Log from iPad/Iphone
Find Size Contributed by Each External Library on iOS
How to Move to the Next Page in Facebook JSON Response Using iOS Sdk
Why Is Swiftui Picker in Form Repositioning After Navigation
Autorelease Pools and When Release Is Called Under iOS
Share Image with Hashtag via Uiactivityviewcontroller (Twitter, Facebook, Instagram)
What the Meaning of Question Mark '' in Swift
Lock iOS App in Single App Mode Programmatically
Is It Safe to Delete SQLite's Wal File
Gem Native Extension Error While Installing Cocoapods
How to Use Coreaudio's Audioconverter to Encode Aac in Real-Time
Attribute Unavailable Warning on iOS Versions Prior to 8.0