iOS键盘弹出通报后js加入购物车动画效果动画怎么解决

iOS开发 编辑框被系统弹出的软键盘遮挡问题
我们在开发注册界面的时候,最后几个注册条件常常容易被弹出的键盘遮挡,如下图:
可以看见,邮箱条件被遮挡掉了,怎么解决呢?我是通过UITextField的代理加计算偏移量:
- (void)viewDidLoad
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.emailTextField.delegate =
- (void)textFieldDidBeginEditing:(UITextField *)textField{
1.取得被遮挡的邮箱的textField的frame
CGRect frame = self.emailTextField.
2.计算被遮挡的textField的bottom代表的高度(Y坐标) 与 能不被键盘遮挡的最大高度(Y坐标) 的距离
int offset = frame.origin.y + 32 - (self.view.frame.size.height - 216);
[UIView animateWithDuration:0.3 animations:^{
if (offset > 0) {
让整个view向上偏移差距
self.view.frame = CGRectMake(0, -offset, self.view.frame.size.width, self.view.frame.size.height);
- (void)textFieldDidEndEditing:(UITextField *)textField{
[UIView animateWithDuration:0.3 animations:^{
编辑结束后重置为原来的
self.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
(window.slotbydup=window.slotbydup || []).push({
id: '2467140',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467141',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467142',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467143',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467148',
container: s,
size: '1000,90',
display: 'inlay-fix'UITextField
首先我们要注册键盘弹出和弹入的通知
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
//Code from Brett Schumann
-(void) keyboardWillShow:(NSNotification *)note{
// get keyboard size and loctaion
CGRect keyboardB
[[note.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] getValue: &keyboardBounds];
NSNumber *duration = [note.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
NSNumber *curve = [note.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey];
// Need to translate the bounds to account for rotation.
keyboardBounds = [self.view convertRect:keyboardBounds toView:nil];
// get a rect for the textView frame
CGRect btnFrame = self.editView.
btnFrame.origin.y = self.view.bounds.size.height - (keyboardBounds.size.height + btnFrame.size.height);
// animations settings
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:[duration doubleValue]];
[UIView setAnimationCurve:[curve intValue]];
[UIView setAnimationDelegate:self];
// set views with new info
self.editView.frame = btnF
// commit animations
[UIView commitAnimations];
- (void) keyboardWillHide:(NSNotification *)note{
NSNumber *duration = [note.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
NSNumber *curve = [note.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey];
// get a rect for the textView frame
CGRect btnFrame = self.editView.
btnFrame.origin.y = self.view.bounds.size.height + btnFrame.size.
// animations settings
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:[duration doubleValue]];
[UIView setAnimationCurve:[curve intValue]];
// set views with new info
self.editView.frame = btnF
// commit animations
[UIView commitAnimations];
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:46382次
积分:1034
积分:1034
排名:千里之外
原创:48篇
转载:33篇
评论:14条
(3)(6)(1)(1)(3)(2)(2)(1)(4)(2)(3)(2)(2)(2)(2)(15)(22)(8)(2)IOS键盘弹出时UIView上移的动画效果
1.添加系统控件监听:一般只在viewDidLoad中添加即可
2.键盘显示调用方法的实现
3.调用uview的上移实现
(1).h文件中声明一个UIView
(2).m文件:将其他需要动画显示的控件add到这个子view中,然后再将子view添加到self.view中,并设置子view的在self.view中的初始位置(这可以在重写loadView方法中实现)
(3).m文件:2中键盘方法调用的自定义的视图上移、下移方法中重新设置子view的位置
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。全局替换NSArray,NSMutableArray,NSDictionary,NSMutableDictionary等集合的方法(比如objectAtIndex:,addObject:,setObject:forKey:等等)去去获取一些安全性时(避免添加nil到数组,或者nil成为字典的key,value等情况)。
也会带来一个问题,在ARC编译环境下:
App弹出键盘后,进入后台,会crash
Thread : Crashed: com.apple.main-thread
libobjc.A.dylib
objc_release + 20
libsystem_blocks.dylib
_Block_release + 256
libobjc.A.dylib
(anonymous namespace)::AutoreleasePoolPage::pop(void*) + 564
CoreFoundation
_CFAutoreleasePoolPop + 28
_wrapRunLoopWithAutoreleasePoolHandler + 76
CoreFoundation
__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
CoreFoundation
__CFRunLoopDoObservers + 360
CoreFoundation
__CFRunLoopRun + 836
CoreFoundation
CFRunLoopRunSpecific + 396
GraphicsServices
GSEventRunModal + 168
UIApplicationMain + 1488
main (main.m:15)
12 libdyld.dylib
打开 Enable Zombie Objects,可以看到崩溃时控制台有输出:
-[UIKeyboardLayoutStar release]: message sent to deallocated
这里谨慎的怀疑是相关操作去release了NSArray或者NSMutableArray对象,但是在我们全局替换那些方法时,是使用了ARC编译的,是不需要手动release的,可能这就造成了多次release.
最直接简单的是去掉这些集合的方法swizzle,但这样会失去原来想要得到的特性
设置这些实现文件的编译选项为-fno-objc-arc
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:5629次
排名:千里之外
(1)(1)(1)(1)(2)(1)}

我要回帖

更多关于 加入购物车动画效果 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信