gpt4 book ai didi

iphone - 为什么我的 UITextView 中不显示键盘?

转载 作者:行者123 更新时间:2023-12-03 19:26:06 27 4
gpt4 key购买 nike

我有一个容器类,它是 View Controller 。
它保存笔记的 UITextView 并有另一个 View Controller 作为 subview ,称为 PDFViewController。该 Controller 中有一组 View Controller (称为 PageViewController)和一个 UIScrollView,因此我可以从数组中滑动不同的 View Controller 。

每个 PageViewController 也有一个 UIScrollView,所以我可以缩放不同的页面。

但是当我显示 UITextView 时,我无法编辑或写入任何内容。
它显示闪烁的光标,但没有键盘并且无法写入文本。
当我突出显示默认文本中的单词时,它会向我显示一些词典选项,但这些单词不会被替换。

我只是不知道问题出在哪里。

container.m( View Controller )

- (void) initNotes {

notesVisible = FALSE;
notes = [[UITextView alloc]initWithFrame:CGRectMake(10, 10, note_width, note_height)];
notes.backgroundColor = [UIColor yellowColor];
notes.font = [UIFont fontWithName:@"Arial" size:24];
notes.text = @"Hier ist Platz für Ihre Notizen";

container = [[UIView alloc] initWithFrame:CGRectMake(start_x, start_y, container_width, container_height)];
container.backgroundColor = [UIColor yellowColor];
[container.layer setShadowColor:[[UIColor blackColor] CGColor]];
[container.layer setShadowOffset:CGSizeMake(2.0, 3.0)];
[container.layer setShadowOpacity:0.6];
[container.layer setShadowRadius:5];
container.layer.shouldRasterize = YES;
[container addSubview:notes];
[self.view addSubview:container];
}

- (void) showTextView {
[UIView beginAnimations:@"MoveAndStrech" context:nil];
[UIView setAnimationDuration:0.4];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

container.frame = CGRectMake(start_x, self.view.center.y-container_height, container_width, container_height);

[UIView commitAnimations];

notesVisible = !notesVisible;
}

- (void) hideTextView {

[UIView beginAnimations:@"MoveAndStrech" context:nil];
[UIView setAnimationDuration:0.4];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];

container.frame = CGRectMake(start_x, start_y, container_width, container_height);

// [notes resignFirstResponder];
[UIView commitAnimations];

notesVisible = !notesVisible;
}

@实现 PDFViewController

- (void)awakeFromNib
{
painting = false;
dataInstance = [PDFDataInstance sharedInstance];
chapter = [dataInstance chapter];
[self getNumberOfPages];
kNumberOfPages = dataInstance.pages;

// Register observer to be called when a cell from BookmarkPDFController is pressed
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didSelectBookmark:)
name:@"bookmarkPressedinPDFView" object:nil];
// Register observer to be called when a cell from BookmarkPDFController is pressed
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(togglePainting:)
name:@"togglePainting" object:nil];

// view controllers are created lazily
// in the meantime, load the array with placeholders which will be replaced on demand
NSMutableArray *controllers = [[NSMutableArray alloc] init];
for (unsigned i = 0; i < kNumberOfPages; i++)
{
[controllers addObject:[NSNull null]];
}
self.viewControllers = controllers;
[controllers release];

// a page is the width of the scroll view
scrollView.pagingEnabled = YES;
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * kNumberOfPages, scrollView.frame.size.height);
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
scrollView.delegate = self;
scrollView.directionalLockEnabled = YES;

currentPage = [[chapter currentPage] integerValue];


// pages are created on demand
// load the visible page
// load the page on either side to avoid flashes when the user starts scrolling
//
// Load pages based on currentPage cause of when coming from bookmarks
[self loadScrollViewWithPage:currentPage];
[self loadScrollViewWithPage:currentPage+1];

// update the scroll view to the appropriate page
CGRect frame = scrollView.frame;
frame.origin.x = frame.size.width * currentPage;
frame.origin.y = 0;
[scrollView scrollRectToVisible:frame animated:YES];


}

- (void)loadScrollViewWithPage:(int)page
{
if (page < 0)
return;
if (page >= kNumberOfPages)
return;

// replace the placeholder if necessary
PageViewController *controller = [viewControllers objectAtIndex:page];
if ((NSNull *)controller == [NSNull null])
{
//page+1 cause CGPDF indexing starts with 1
controller = [[PageViewController alloc] initWithPageNumberAndUrl:page+1: [chapter urlOnFilesystem]];
[viewControllers replaceObjectAtIndex:page withObject:controller];
[controller release];
}

// add the controller's view to the scroll view
if (controller.view.superview == nil)
{
CGRect frame = scrollView.frame;
frame.origin.x = frame.size.width * page;
frame.origin.y = 0;
controller.view.frame = frame;

[scrollView addSubview:controller.view];

}
}

TextView 委托(delegate)

- (void)textViewDidBeginEditing:(UITextView *)textView {

NSLog(@"begin editing");
}

- (BOOL)textView:(UITextView *)aTextView shouldChangeTextInRange:(NSRange)aRange replacementText:(NSString*)aText
{
NSLog(@"something changed");
return YES;
}

最佳答案

只是想在这里添加另一种可能性。在iOS模拟器中,确保“硬件/键盘/连接硬件键盘”未被选中。我花了几个小时才弄清楚这一点。我想我是通过不小心按下快捷键来切换该选项的。体验不好:(

Menus

如图所示,应取消选中“连接硬件键盘”。

关于iphone - 为什么我的 UITextView 中不显示键盘?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6304599/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com