草庐IT

ios resignFirstResponder 重置动画

coder 2024-01-13 原文

首先为我糟糕的英语感到抱歉!!

在我的应用程序中有一个 UIViewController 并且 UIView 在 subViewLogin 中被称为 subViewLogin 有 2 个 UITextField 被称为用户名和密码。当我的应用程序运行时 subViewLogin 被 UIViewAnimationCurveLinear 移动到位置。但是当我完成编辑 UITextField(调用 resignFirstResponder)时 subViewLogin 卷土重来定位。为什么?我怎样才能防止 subViewLogin 重新定位?

这是我的代码。

//LoginViewController.h
#import <UIKit/UIKit.h>

@interface LoginViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *username;
@property (weak, nonatomic) IBOutlet UITextField *password;
@property (weak, nonatomic) IBOutlet UIImageView *background;
@property (weak, nonatomic) IBOutlet UIImageView *logoEnergy;
@property (weak, nonatomic) IBOutlet UIImageView *logoKmutl;
@property (weak, nonatomic) IBOutlet UIImageView *logoProjectname;
@property (weak, nonatomic) IBOutlet UIView *subviewLogin;

- (void)advoidSubviewFromKeyboard;
- (IBAction)usernameAndPasswordBeginEdit;
- (IBAction)dismissKeyboard;
@end

//LoginViewController.m
#import "LoginViewController.h"
@implementation LoginViewController

const float keyBoardPortraitHeight = 216;
const float keyBoardLandscapeHeight = 162;

@synthesize username, password, background, logoEnergy, logoKmutl, logoProjectname;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization

    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]];
    UIView *subview = self.subviewLogin;
    subview.frame = CGRectMake(subview.frame.origin.x, self.view.frame.size.height, subview.frame.size.width, subview.frame.size.height);
}

- (void)viewDidAppear:(BOOL)animated
{
    [UIView
    animateWithDuration:0.3
    delay: 0.0
    options: UIViewAnimationCurveLinear
    animations:^{
        UIView *subview = self.subviewLogin;
        subview.frame = CGRectMake(subview.frame.origin.x, self.view.frame.size.height-subview.frame.size.height-30, subview.frame.size.width, subview.frame.size.height);
    }
    completion:^(BOOL finished){

    }
    ];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)advoidSubviewFromKeyboard
{
    [UIView
     animateWithDuration:0.3
     delay: 0.0
     options: UIViewAnimationCurveLinear
     animations:^{
         self.view.frame = CGRectMake(self.view.frame.origin.x, -keyBoardPortraitHeight+30, self.view.frame.size.width, self.view.frame.size.height);
     }
     completion:^(BOOL finished){

     }
     ];
}

- (IBAction)usernameAndPasswordBeginEdit
{
    [self advoidSubviewFromKeyboard];
}

- (IBAction)dismissKeyboard
{
    NSLog(@"dismiss");
    //[self.username becomeFirstResponder];
    //[self.username resignFirstResponder];
    [self.subviewLogin endEditing:YES];
    //[self.view endEditing:YES];
}
@end

最佳答案

即使很久以前就提出了这个问题,但这种行为现在仍然存在。我已经使用约束而不是更新元素的框架来解决它。示例:

func expand(with view: UIView, constraint: NSLayoutConstraint) {
    constraint.constant = self.isExpanded ? self.minHeight : self.maxHeight //set needed constant here
    UIView.animate(withDuration: expandDuration, animations: {
        self.arrowImageView.transform = self.isExpanded ? .identity : CGAffineTransform(rotationAngle: self.topAngle)
        view.layoutSubviews() //layout constraint's view subviews
    }) { _ in
        self.isExpanded = !self.isExpanded
    }
}

关于ios resignFirstResponder 重置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14091683/

有关ios resignFirstResponder 重置动画的更多相关文章

  1. Unity 3D 制作开关门动画,旋转门制作,推拉门制作,门把手动画制作 - 2

    Unity自动旋转动画1.开门需要门把手先动,门再动2.关门需要门先动,门把手再动3.中途播放过程中不可以再次进行操作觉得太复杂?查看我的文章开关门简易进阶版效果:如果这个门可以直接打开的话,就不需要放置"门把手"如果门把手还有钥匙需要旋转,那就可以把钥匙放在门把手的"门把手",理论上是可以无限套娃的可调整参数有:角度,反向,轴向,速度运行时点击Test进行测试自己写的代码比较垃圾,命名与结构比较拉,高手轻点喷,新手有类似的需求可以拿去做参考上代码usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;u

  2. LVGL V8动画 - 2

    动画/*INITIALIZEANANIMATION 初始化一个动画*-----------------------*/lv_anim_ta;lv_anim_init(&a);/*MANDATORYSETTINGS 必选设置*------------------*//*Setthe"animator"function 设置“动画”功能*/lv_anim_set_exec_cb(&a,(lv_anim_exec_xcb_t)lv_obj_set_x);/*Setthe"animator"function*/lv_anim_set_var(&a,obj);/*Lengthoftheanim

  3. ruby-on-rails - 如何完全重新加载 ActiveRecord 以重置其内存值? - 2

    在RSpec测试中,我创建了一个记录,其中包含多个内存值。foo.reload对对象的属性按预期工作,但内存的属性仍然存在。到目前为止,它通过完全重新创建对象来工作:foo=Foo.find(123)但在我的例子中,查找记录的逻辑实际上更复杂。什么是完全重新加载记录并删除所有内存值的好方法? 最佳答案 好的方法是您已有的方法:完全重新创建对象。您不能以任何简单的“Rails”方式“重新加载”对象的内存值,因为内存属性不是Rails或ActiveRecord的功能。两者都不知道您是如何内存方法的。

  4. ruby-on-rails - AuthLogic perishable_token 在每次请求时重置 - 2

    在我的用户模型中我有:acts_as_authenticdo|c|c.perishable_token_valid_for=30.minutesend在我的应用程序Controller中,我有标准样板代码:defcurrent_user_sessionreturn@current_user_sessionifdefined?(@current_user_session)@current_user_session=UserSession.findenddefcurrent_userreturn@current_userifdefined?(@current_user)@current_u

  5. ruby - Carrierwave + MiniMagick - 如何将动画 GIF 压缩到第一帧? - 2

    有人知道如何使用Carrierwave+MiniMagick将动画GIF压缩到第一帧吗? 最佳答案 我认为MiniMagick有一些变化,因为我只花了三个小时试图找出为什么Andrey的代码对我不起作用。我收到以下错误:ActiveRecord::RecordInvalid(Validationfailed:ImageFailedtomanipulatewithMiniMagick,maybeitisnotanimage?OriginalError:Command("mogrify-scene/var/folders/0o/0oqN

  6. ruby - 如何在 Ruby 中重置类定义? - 2

    如何在Ruby中从内存中完全删除一个类?我正在处理两个文件:#foo.rbrequire'expensive_library'classFoo和:#foo_tests.rbrequire'foo'require'test/unit'classfoo_testsExpensiveLibrary很贵;加载需要超过15秒。这对于在开发过程中重复运行测试来说太长了(测试套件的其余部分用时不到1秒)。我通过启动Pry并编写一个函数来加载这两个文件并调用Test::Unit:Autorunner.run来解决昂贵库的加载时间问题。这在第一次运行的测试中仍然有15秒的暂停,但随后的测试运行每次运行不

  7. 上传到 S3 时 Ruby Backup gem 失败。 37 分钟后连接重置 - 2

    备份为250MB。我认为这不是很大,但问题似乎随着规模的增加而增加。从下面的备份gem登录。注意时间跨度;上传大约37分钟后,我收到了连接重置。[2015/10/3009:20:40][message]Storage::S3startedtransferring'2015.10.30.09.20.01.myapp_postgres.tar'tobucket'myapp-backups'.[2015/10/3009:57:06][error]ModelError:BackupforBackupPostgreSQL(myapp_postgres)Failed![2015/10/3009:5

  8. ruby - 重置 IRB 控制台 - 2

    如何告别在irbsession中定义的所有常量、对象等,回到干净的状态?“在”是指不操纵子session。 最佳答案 类型exec($0)在您的irb控制台session中。 关于ruby-重置IRB控制台,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/10271676/

  9. ruby-on-rails - 如何在 Ajax 请求处理期间显示动画图标 - Rails 3 - 2

    我正在尝试为每个ajax请求显示一个加载指示器,我在Rails3应用程序中工作。HTML:"loading-indicator",:style=>"display:none")%>CSS:#loading-indicator{position:absolute;left:10px;top:10px;}loading.js:我放在assest/javascripts/$(document).ready(function(){$(document).ajaxSend(function(event,request,settings){$('#loading-indicator').show(

  10. 对 https 的 Ruby 请求 - "in ` read_nonblock':连接由对等方重置(Errno::ECONNRESET)” - 2

    这是我的代码domain='http://www.google.com'url=URI.parse"https://graph.facebook.com/fql?q=SELECT%20url,normalized_url%20FROM%20link_stat%20WHERE%20url='#{domain}'"req=Net::HTTP::Get.newurl.pathres=Net::HTTP.start(url.host,url.port){|http|http.requestreq}putsres.body它给了我/home/alex/.rvm/rubies/ruby-2.0.0

随机推荐