iOS UITextField框架没有提交

时间:2014-02-10 19:10:43

标签: ios uikit uitextfield

我在更新UI方面遇到了一个奇怪的问题。在下面的代码中,我写了一些评论来阻止我所说的“第1节”和“第2节”。无论如何,第1部分完美无瑕地工作并提交动画,但如果我在代码中有第1部分,则第2部分不起作用。框架已设置,但动画从未执行且保持静止

当我有两个部分时,它会这样做: http://cl.ly/image/2p3H0x3n3W1F/Screenshot%202014.02.10%2014.07.54.png (注意步进器下面的文本字段不会移动)

当我刚刚第2节时,它会这样做: http://cl.ly/image/2H0C1p2M1M37/Screenshot%202014.02.10%2014.07.32.png (步进器正确移动,但由于第1节不存在,因此不会创建中间文本域)

我已经检查过的事情:

  1. 确保我在主线程(我是)
  2. 检查我的所有商店并确保所有变量都不是零(它们不是)
  3. 我注意到endAddressTextfield.frame没有显示完成块中的更改,但是在动画块中没有。因此,在动画块中,它是正确的,在完成块中,它仍处于旧位置

    [动画块]

    2014-02-10 14:15:38.253 traffic[1163:60b] animatedBegin frame: {{20, 20}, {280, 30}}
    2014-02-10 14:15:38.253 traffic[1163:60b] animatedMid frame: {{20, 95}, {280, 30}}
    2014-02-10 14:15:38.254 traffic[1163:60b] animatedMid frame: {{20, 140}, {280, 30}}
    2014-02-10 14:15:38.254 traffic[1163:60b] animatedEnd frame: {{20, 185}, {280, 30}}
    

    [完成块]

    2014-02-10 14:15:38.508 traffic[1163:60b] Begin frame: {{20, 20}, {280, 30}}
    2014-02-10 14:15:38.509 traffic[1163:60b] Mid frame: {{20, 95}, {280, 30}}
    2014-02-10 14:15:38.511 traffic[1163:60b] Mid frame: {{20, 140}, {280, 30}}
    2014-02-10 14:15:38.512 traffic[1163:60b] End frame: {{20, 95}, {280, 30}}
    

    目标是让endAddressTextfield移动到航点以下。

    ·H

    @interface CreateCustomRouteViewController : UIViewController{
    
        __weak IBOutlet UITextField *startAddressTextfield;
        NSMutableArray* waypointTextfields;
        __weak IBOutlet UIStepper *waypointStepper;
        __weak IBOutlet UITextField *endAddressTextfield;
    }
    - (IBAction)waypointStepperValueChanged:(id)sender;
    
    @end
    

    的.m

    #import "CreateCustomRouteViewController.h"
    
    @interface CreateCustomRouteViewController ()
    
    @end
    
    @implementation CreateCustomRouteViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        waypointTextfields = [[NSMutableArray alloc] init];
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
    }
    
    - (IBAction)waypointStepperValueChanged:(UIStepper*)sender {
        [UIView animateWithDuration:0.25 animations:^{
            CGRect frame;
            //beginSection1
            if ([waypointTextfields count] > sender.value){
                [[waypointTextfields lastObject] removeFromSuperview];
                [waypointTextfields removeLastObject];
            }else{
                frame = startAddressTextfield.frame;
                frame.origin.y = 50.0f + (sender.value) * 45.0f;
                UITextField* tmp = [[UITextField alloc] initWithFrame:frame];
                tmp.borderStyle = UITextBorderStyleRoundedRect;
                tmp.backgroundColor = [UIColor greenColor];
                tmp.alpha = 0.25f;
                [self.view addSubview:tmp];
                [waypointTextfields addObject:tmp];
            }
            //endSection1
    
            //startSection2
            frame = endAddressTextfield.frame;
            frame.origin.y = 95.0f + (sender.value) * 45.0f;
            endAddressTextfield.frame = frame;
            //endSection2 
        }];
    }
    
    @end
    

    故事板:

    http://cl.ly/image/3d3f2M2d370g/Screen%20Shot%202014-02-10%20at%202.02.46%20PM.png

    网点:

    http://cl.ly/image/0U2M2f202B3S/Screen%20Shot%202014-02-10%20at%202.11.44%20PM.png

1 个答案:

答案 0 :(得分:0)

自动布局是问题。 SIGH。