Ios 有人能帮我理解为什么我的观点没有改变,以及我如何解决它吗?
我是IOS编程(以及一般编程)的初学者,我不明白为什么当键盘出现在屏幕上时,我的代码不会像我所希望的那样改变屏幕上的所有内容。有人能帮我理解我在这里遗漏了什么吗 ViewController.hIos 有人能帮我理解为什么我的观点没有改变,以及我如何解决它吗?,ios,objective-c,Ios,Objective C,我是IOS编程(以及一般编程)的初学者,我不明白为什么当键盘出现在屏幕上时,我的代码不会像我所希望的那样改变屏幕上的所有内容。有人能帮我理解我在这里遗漏了什么吗 ViewController.h @interface ViewController : UIViewController <UITextFieldDelegate> { } @property (strong, nonatomic) IBOutlet UITextField *firstRoommateTex
@interface ViewController : UIViewController <UITextFieldDelegate> {
}
@property (strong, nonatomic) IBOutlet UITextField *firstRoommateTextField;
@property (strong, nonatomic) IBOutlet UITextField *secondRoommateTextField;
@property (strong, nonatomic) IBOutlet UILabel *calculatedValueLabel;
- (IBAction)calculateButton:(UIButton *)sender;
- (IBAction)textFieldDismiss2:(id)sender;
- (IBAction)textFieldDismiss1:(id)sender;
@end
首先检查textfield对象是否已分配给代理..即。
\u firstRoommateTextField.delegate=self;
_secondRoommateTextField.delegate=self代码>
然后检查委托方法是否被调用
最后试一下这个,而不是CGRectOffset,试一下CGRectMake。我想你忘了为文本字段设置委托,你可以设置为
_firstRoommateTextField.delegate=self;
_secondRoommateTextField.delegate=self;
在viewDidLoad中
或者从故事板
按住ctrl键并从textField拖动到ViewController(视图控制器场景正下方的右上角),然后选择“委派”。如果您刚刚开始,在堆栈溢出问题上提出这样广泛的问题不是您需要的地方。你应该找到一本好书或一系列在线教程。看一看。《大书呆子牧场》的书非常好,很多人都喜欢iTunes U上的斯坦福iOS课程。祝你好运!
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize firstRoommateTextField = _firstRoommateTextField;
@synthesize secondRoommateTextField = _secondRoommateTextField;
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void) animateTextField: (UITextField*) textField up: (BOOL) up
{
const int movementDistance = 210; // tweak as needed
const float movementDuration = 0.3f; // tweak as needed
int movement = (up ? -movementDistance : movementDistance);
[UIView beginAnimations: @"anim" context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: movementDuration];
self.view.frame = CGRectOffset(self.view.frame, 0, movement);
[UIView commitAnimations];
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
[self animateTextField: textField up: YES];
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
[self animateTextField: textField up: NO];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}