我在更新我的UI時遇到了一個奇怪的問題。在下面的代碼中,我寫了阻止我所稱的「第1部分」和「第2部分」的評論。無論如何,第1部分完美地工作,它提交動畫,但如果我在代碼中有第1部分,則第2部分不起作用。該框架設置,但動畫永遠不會進行,它保持靜止iOS UITextField幀未提交
當我有兩個部分它這樣做: 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節不存在,也沒有創造的中介文本框)
事情我已經檢查:
- 確保我的主線程(我)
- 檢查我所有的網點,並確保沒有一個變量是不是零上(他們不是)
我注意到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