Một lúc trước, tôi nhớ đã nhìn thấy một hằng số của một số loại định nghĩa tốc độ hoạt hình của Bàn phím trên iPhone và tôi không thể cho cuộc sống của tôi nhớ nơi tôi nhìn thấy nó .... bất kỳ cái nhìn sâu sắc?Tỷ lệ hoạt ảnh bàn phím mặc định của iPhone là gì?
Trả lời
- (NSTimeInterval)keyboardAnimationDurationForNotification:(NSNotification*)notification
{
NSDictionary* info = [notification userInfo];
NSValue* value = [info objectForKey:UIKeyboardAnimationDurationUserInfoKey];
NSTimeInterval duration = 0;
[value getValue:&duration];
return duration;
}
Nếu bạn đến đây tìm kiếm câu trả lời MonoTouch, hãy nhìn không xa hơn 'e.AnimationDuration'. –
Lưu ý rằng để chính xác, bạn cũng nên điều chỉnh cho các phím hoạt ảnh khác, như 'UIKeyboardAnimationCurveUserInfoKey'. – Rick
@Dan, tôi là người dùng MonoTouch, nhưng 'e' là gì? –
UIKeyboardAnimationDurationUserInfoKey Chìa khóa cho đối tượng NSValue có chứa gấp đôi xác định thời lượng của hoạt ảnh trong vài giây.
Hey mate, là chìa khóa UIKeyboardAnimationDurationUserInfoKey trong từ điển thông tin người dùng của thông báo ???? -thx – ShortCircuit
Vì đây là lần đầu tiên google hit, tôi muốn chỉ ra rằng cứng mã hóa 0.3 sẽ có nghĩa rằng quan điểm của bạn không đúng cách sẽ làm động khi người dùng quốc tế (ví dụ như Nhật Bản) trao đổi giữa bàn phím kích thước khác nhau (khi hành động đó phải là ngay lập tức).
Luôn sử dụng thông số UIKeyboardAnimationDurationUserInfoKey của từ điển userInfo - số này được đặt thành 0 khi người dùng nhấp qua bàn phím.
NB: tại thời điểm viết (iOS 5.1.1) thời lượng mặc định là 0,25 giây. Vì vậy, như @greenlight nói, không bao giờ khó mã này - sử dụng dữ liệu từ từ điển userInfo của thông báo. –
Để thêm một chút nữa vào những gì Shaggy Frog đã viết. Thực hiện đầy đủ sẽ là một cái gì đó như:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardMovement:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardMovement:)
name:UIKeyboardWillHideNotification
object:nil];
-(void)keyboardMovement:(NSNotification *)notification{
if (_numericKeyboardShowing == false){
[UIView animateWithDuration:[self keyboardAnimationDurationForNotification:notification] delay:0
options:UIViewAnimationCurveEaseInOut
animations:^ {
self.bottomContainerView.center = CGPointMake(self.bottomContainerView.center.x, (self.bottomContainerView.center.y - 218));
}
completion:NULL];
_numericKeyboardShowing = true;
}
else{
[UIView animateWithDuration:[self keyboardAnimationDurationForNotification:notification] delay:0
options:UIViewAnimationCurveLinear
animations:^ {
self.bottomContainerView.center = CGPointMake(self.bottomContainerView.center.x, (self.bottomContainerView.center.y + 218));
}
completion:NULL];
_numericKeyboardShowing = false;
}
- (NSTimeInterval)keyboardAnimationDurationForNotification:(NSNotification *)notification
{
NSDictionary *info = [notification userInfo];
NSValue* value = [info objectForKey:UIKeyboardAnimationDurationUserInfoKey];
NSTimeInterval duration = 0;
[value getValue:&duration];
return duration;
}
UIKeyboardAnimationDurationUserInfoKey bây giờ là một đối tượng NSNumber, mà làm cho mã ngắn hơn.
- (void)keyboardWillShowNotification:(NSNotification *)notification
{
NSDictionary *info = [notification userInfo];
NSNumber *number = [info objectForKey:UIKeyboardAnimationDurationUserInfoKey];
double duration = [number doubleValue];
}
Một lớp lót: 'double duration = [notification.userInfo [UIKeyboardAnimationDurationUserInfoKey] doubleValue];' –
Trong Swift code của bạn sẽ trông như thế này:
let keyboardSize: CGSize = userInfo[UIKeyboardFrameBeginUserInfoKey]!.CGRectValue.size
let animationDuration = ((userInfo[UIKeyboardAnimationDurationUserInfoKey]) as! NSNumber).floatValue
let animationOptions = ((userInfo[UIKeyboardAnimationCurveUserInfoKey]) as! NSNumber).unsignedLongValue
UIView.animateWithDuration(NSTimeInterval(animationDuration), delay: 0,
options: UIViewAnimationOptions(rawValue: animationOptions),
animations: {() -> Void in
self.view.frame.origin.y += keyboardSize.height
},
completion: nil)
Swift 4 - làm việc cho tôi:
if let duration = notification.userInfo?[UIKeyboardAnimationDurationUserInfoKey] as? Double {
UIView.animate(withDuration: duration, animations: {
self.view.layoutIfNeeded()
})
}
Trong chế độ gỡ lỗi của tôi duration
được 3.499999
- 1. Mặc định bàn phím số của iPhone
- 2. Tỷ lệ hình ảnh theo tỷ lệ
- 3. Hoạt ảnh UIVIew - Chia tỷ lệ + Dịch
- 4. Bàn phím iPhone tùy chỉnh
- 5. Tỷ lệ hình ảnh iPhone được chụp từ AVCaptureSession
- 6. Phím shift trên bàn phím iPhone bị vô hiệu hóa
- 7. iPhone datepicker thay vì bàn phím?
- 8. Tỷ lệ chia tỷ lệ trong hình ảnh Android?
- 9. Định dạng BMP cho Hình ảnh tỷ lệ xám là gì?
- 10. iPhone: Không thể tìm thấy bàn phím có hỗ trợ loại 8 cho bàn phím iPhone-Portrait-DecimalPad; sử dụng Mặc định?
- 11. Tỷ lệ -webkit-min-device-pixel-ratio: 2 là gì?
- 12. chia tỷ lệ hình ảnh, nhưng giữ tỷ lệ của hình ảnh
- 13. Tùy chỉnh bàn phím iPhone
- 14. CGAffineTransform và chia tỷ lệ thành tâm của hình ảnh
- 15. Điều chỉnh tỷ lệ là gì?
- 16. Tôi làm cách nào để tạo chuỗi hoạt ảnh theo tỷ lệ bằng iPhone UIImageView?
- 17. Phím tắt intellisense mặc định trong vs2008 là gì?
- 18. ẩn bàn phím mặc định khi nhấp chuột trong android
- 19. Tỷ lệ hình ảnh UISegmentedControl
- 20. Nút mặc định trên bàn phím iOS dịch
- 21. Kích hoạt sự kiện nhấn phím bàn phím mà không cần nhấn phím từ bàn phím
- 22. iPhone: Khối bàn phím màn hình
- 23. iOS: Tắt hoạt ảnh UITableView khi bàn phím hiển thị
- 24. Tỷ lệ màn hình chia tỷ lệ canvas của Android
- 25. Kích thước bàn phím số 5 của iPhone
- 26. Cách xác định tỷ lệ cỡ ảnh nào gần nhất là
- 27. Thay đổi màu của Bàn phím trong iphone
- 28. Đặt ngôn ngữ bàn phím iPhone
- 29. Tôi có thể lập trình kích hoạt nút "chuyển sang bàn phím số" trên bàn phím iPhone
- 30. image Chia tỷ lệ hình ảnh hộp
Nó luôn luôn 0.3 ! : P –
Kiểu bàn phím và hành vi xoay được thay đổi giữa 2.2.1 và 3.0; ai nói rằng họ sẽ không thay đổi tốc độ hoạt hình trong các phiên bản sau? – rpetrich
Một câu trả lời tốt hơn cho điều này có thể được tìm thấy tại http://stackoverflow.com/a/19235995/39946 Nó cung cấp thời gian chính xác và đường cong animtation chính xác. –