2013-05-30 47 views
0

我有一個UIScrollView和在UIScrollView我有UITextFeild在那UIScrollView。我的問題是,點擊UITextfFeildUIScrollView變得比我設置的小。點擊UITextField使UIScrollView更小

設置我UIScrollView

-(void) viewDidAppear:(BOOL)animated { 
myScrollView.contentSize = CGSizeMake (320,800); 
} 

當我點擊UITextfeildUIScrollView被800更小的約500去?

#import "TestViewController.h" 

@interface TestViewController() 

@end 

@implementation TestViewController 
AVAudioPlayer *player; 

@synthesize myScrollView; 
@synthesize questionLabel, actionBarLabel, questionPlaceholder, commentsLabel; 
@synthesize imageView, firstNameTextField,commentsTextField; 

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
// Do any additional setup after loading the view, typically from a nib. 
myScrollView.maximumZoomScale = 0.0; 
myScrollView.minimumZoomScale = 0.0; 
myScrollView.clipsToBounds = YES; 
myScrollView.delegate = self; 
[myScrollView addSubview:imageView]; 
[myScrollView setScrollEnabled:YES]; 
[myScrollView addSubview:questionLabel]; 
[myScrollView addSubview:firstNameTextField]; 
[myScrollView addSubview:commentsTextField]; 
[myScrollView addSubview:actionBarLabel]; 
[myScrollView addSubview:questionPlaceholder]; 
[myScrollView addSubview:commentsLabel]; 

UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[btn1 setFrame:CGRectMake(10.0f, 600.0f, 300.0f, 42.0f)]; 
[btn1 setTitle:[NSString stringWithFormat:@"Choose an Option"] forState:UIControlStateNormal]; 
[btn1 addTarget:self action:@selector(showActionSheet:) forControlEvents:UIControlEventTouchUpInside]; 
[super viewDidLoad]; 
[self.myScrollView addSubview:btn1]; 

[self performSelector:@selector(showGradientForQuestions1) withObject:nil afterDelay:0]; 

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
NSData *imageData = [defaults dataForKey:@"image"]; 
UIImage *contactImage = [UIImage imageWithData:imageData]; 

NSString *frontName = [defaults objectForKey:@"firstname"]; 
NSString *comments = [defaults objectForKey:@"commentsText"]; 

// Update the UI elements with the saved data 
imageView.image = contactImage; 
firstNameTextField.text = frontName; 
commentsTextField.text = comments; 
firstNameTextField.delegate = self; 
commentsTextField.delegate = self; 
} 

- (void)didReceiveMemoryWarning 
{ 
[super didReceiveMemoryWarning]; 
} 

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker 
{ 
[self dismissViewControllerAnimated:YES completion:nil]; 
} 

- (IBAction) save:(id)sender 
{ 
[firstNameTextField resignFirstResponder]; 
[commentsTextField resignFirstResponder]; 

// Create instace of NSData 
UIImage *contactImage = imageView.image; 
NSData *imageData = UIImageJPEGRepresentation(contactImage, 100); 
NSString *frontName = [firstNameTextField text]; 
NSString *comments = [commentsTextField text]; 

// Store the data 
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 

[defaults setObject:imageData forKey:@"image"]; 
[defaults setObject:frontName forKey:@"firstname"]; 
[defaults setObject:comments forKey:@"commentsText"]; 

[defaults synchronize]; 

NSLog(@"Data saved"); 

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Data Saved!" message:@" Successfully saved to cache" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; 
[alert show]; 

} 

- (void)viewDidUnload 
{ 
imageView = nil; 
firstNameTextField = nil; 
commentsTextField = nil; 
myScrollView = nil; 
[super viewDidUnload]; 
// Release any retained subviews of the main view. 
// e.g. self.myOutlet = nil; 
} 

-(BOOL) textFieldShouldReturn:(UITextField *)textField{ 

[firstNameTextField resignFirstResponder]; 
[commentsTextField resignFirstResponder]; 
[imageView resignFirstResponder]; 
[myScrollView resignFirstResponder]; 
[self.navigationController setNavigationBarHidden:NO]; 

return YES; 
} 

-(void) viewDidAppear:(BOOL)animated { 
myScrollView.contentSize = CGSizeMake (320,800); 
} 
@end 

enter image description here

+0

爲什麼你希望你的滾動視圖比視圖的實際內容高得多? –

+0

因爲我最終需要那個空間來填寫。對於矩,如果您看到我已將按鈕設置爲600,但它隱藏在圖像中,並且在編輯文本字段後無法滾動到按鈕600。 –

+0

您確定您的scoroll的contentSize變小或滾動視圖向上滾動嗎? – danypata

回答

0

是它可能是因爲你的滾動視圖剪輯界限?

myScrollView.clipsToBounds = YES; 
+0

Nah抱歉,試圖將剪輯註釋掉。沒有工作相同的問題。 –

0

當你點擊TextView的文本框或鍵盤來了,隱藏在屏幕的一部分,您將無法直到鍵盤去滾動視圖的其餘部分。嘗試增加textFieldDidBeginEditing函數中滾動視圖的高度,並減少textFieldDidEndEditing函數中的相同數量。

scrollView.contentSize=CGSizeMake(scrollView.contentSize.width,scrollView.contentSize.height+KeyBoardSizePixel);