无法滚动ScrollView

时间:2012-04-28 10:19:03

标签: ios keyboard scrollview hidden

使用xcode 4.3.2

我是新手,所以请保持简单的答案。我试图按照例子但没有任何作用。我有一个包含文本字段的页面。底部被键盘隐藏。我想要的是能够向上滚动以便我可以填写那些隐藏的字段。我附上了我的.m文件。

#import "Engine Editor.h"

@interface Engine_Editor 

@end

@implementation Engine_Editor
@synthesize Enginescroll;
@synthesize MainEngineField;
@synthesize MainSerialField;
@synthesize MainServiceField;
@synthesize AuxEngineField;
@synthesize AuxSerialField;
@synthesize AuxServiceField;
@synthesize BLANK;
@synthesize ReturnEngine;

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

 - (void)viewDidLoad
  {
 self.MainEngineField.text=((ViewController *)self.presentingViewController).MainEngineLabel.text;
 self.MainSerialField.text=((ViewController *)self.presentingViewController).MainSerialLabel.text;
 self.MainServiceField.text=((ViewController *)self.presentingViewController).MainServiceLabel.text;
 self.AuxEngineField.text=((ViewController *)self.presentingViewController).AuxEngineLabel.text;
 self.AuxSerialField.text=((ViewController *)self.presentingViewController).AuxSerialLabel.text; 
 self.AuxServiceField.text=((ViewController *)self.presentingViewController).AuxServiceLabel.text;



[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
[self setEnginescroll:nil];
[self setMainEngineField:nil];
[self setMainSerialField:nil];
[self setMainServiceField:nil];
[self setAuxEngineField:nil];
[self setAuxSerialField:nil];
[self setAuxServiceField:nil];
[self setReturnEngine:nil];
[self setBLANK:nil];

[Enginescroll setScrollEnabled:YES];
[Enginescroll setShowsVerticalScrollIndicator:YES];
[Enginescroll setFrame:CGRectMake(0, 55, 320, 320)];
[Enginescroll setContentSize:CGSizeMake(320, 600)];



[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (IBAction)DismissEditor:(id)sender {

((ViewController *)self.presentingViewController).MainEngineLabel.text=self.MainEngineField.text;
[self dismissViewControllerAnimated:YES completion:Nil];
((ViewController *)self.presentingViewController).MainSerialLabel.text=self.MainSerialField.text;
[self dismissViewControllerAnimated:YES completion:Nil];
((ViewController *)self.presentingViewController).MainServiceLabel.text=self.MainServiceField.text;
[self dismissViewControllerAnimated:YES completion:Nil];
((ViewController *)self.presentingViewController).AuxEngineLabel.text=self.AuxEngineField.text;
[self dismissViewControllerAnimated:YES completion:Nil];
((ViewController *)self.presentingViewController).AuxSerialLabel.text=self.AuxSerialField.text;
[self dismissViewControllerAnimated:YES completion:Nil];
((ViewController *)self.presentingViewController).AuxServiceLabel.text=self.AuxServiceField.text;
[self dismissViewControllerAnimated:YES completion:Nil];

}

- (IBAction)HideKeyBoard:(id)sender {
}
@end

1 个答案:

答案 0 :(得分:1)

您可以注册UIKeyboardDidShowNotification并设置滚动视图的contentInset,使底部插图等于键盘框架的高度(请参阅通知的UIKeyboardFrameEndUserInfoKey键{{1} }})。同样,当您收到userInfo时,只需将UIKeyboardWillHideNotification重置为contentInset