Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 单击UITextField可使UIScrollView变小_Ios_Objective C_Uiscrollview_Uitextfield - Fatal编程技术网

Ios 单击UITextField可使UIScrollView变小

Ios 单击UITextField可使UIScrollView变小,ios,objective-c,uiscrollview,uitextfield,Ios,Objective C,Uiscrollview,Uitextfield,我有一个UIScrollView,在UIScrollView中我有UITextFeild,在UIScrollView中。我的问题是,单击UITextfFeild后,UIScrollView变得比我设置的要小 我设置我的UIScrollView: -(void) viewDidAppear:(BOOL)animated { myScrollView.contentSize = CGSizeMake (320,800); } 当我点击uitextfield时,UIScrollView从800变小到

我有一个
UIScrollView
,在
UIScrollView
中我有
UITextFeild
,在
UIScrollView
中。我的问题是,单击
UITextfFeild
后,
UIScrollView
变得比我设置的要小

我设置我的
UIScrollView

-(void) viewDidAppear:(BOOL)animated {
myScrollView.contentSize = CGSizeMake (320,800);
}
当我点击
uitextfield
时,
UIScrollView
从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

这可能是因为您的scrollView剪辑到了边界吗

myScrollView.clipsToBounds = YES;

当您单击textview或textfield时,键盘会出现并隐藏屏幕的一部分,在键盘打开之前,您将无法滚动视图的其余部分。尝试在
textfielddebeginediting
功能中增加滚动视图的高度,并在
textfielddendediting
功能中减少相同的高度

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

为什么您希望您的滚动视图比视图的实际内容高出这么多?因为我最终需要填充该空间。目前,如果您看到我将一个按钮设置为600,但它隐藏在图像中,在编辑文本字段后,我无法滚动到600处的按钮。您确定您的scoroll的contentSize变小或滚动视图向上滚动吗?是的,UIScrollview向上滚动,但当我想再次向下滚动到该按钮时,它不允许我。你在文本字段委托方法中写了什么?不,很抱歉试图注释掉剪辑到边界。没有解决同样的问题。