相关疑难解决方法(0)

在不使用私有API的情况下获取当前的第一响应者

我在一周前提交了我的应用程序,今天收到了可怕的拒绝电子邮件.它告诉我我的应用程序无法被接受,因为我使用的是非公共API; 具体来说,它说,

应用程序中包含的非公共API是firstResponder.

现在,违规的API调用实际上是我在SO上找到的解决方案:

UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
UIView   *firstResponder = [keyWindow performSelector:@selector(firstResponder)];
Run Code Online (Sandbox Code Playgroud)

如何在屏幕上显示当前的第一响应者?我正在寻找一种不会让我的应用被拒绝的方法.

cocoa-touch objective-c first-responder

334
推荐指数
15
解决办法
15万
查看次数

使用Swift使用键盘移动视图

我有一个应用程序,在视图的下半部分有一个文本字段.这意味着当我输入文本字段时键盘覆盖文本字段.

如何在打字时向上移动视图以便我可以看到我正在键入的内容,然后在键盘消失时将其移回原来的位置?

我到处都看,但所有解决方案似乎都在Obj-C中,我还没有完全转换.

任何帮助将不胜感激.

uikit uikeyboard nsnotificationcenter ios swift

257
推荐指数
15
解决办法
17万
查看次数

选择文本字段时,使UITableView滚动

经过大量的反复试验,我放弃并提出问题.我见过很多人有类似的问题,但无法得到所有正确的答案.

我有一个UITableView由自定义单元格组成的.单元格由5个文本字段组成,彼此相邻(有点像网格).

当我尝试滚动并编辑底部的单元格时UITableView,我无法将单元格正确放置在键盘上方.

我已经看到很多关于改变视图大小的答案......但到目前为止它们都没有很好地工作.

任何人都可以用具体的代码示例澄清"正确"的方法吗?

iphone keyboard scroll uitableview ios

247
推荐指数
17
解决办法
19万
查看次数

当键盘快速显示时移动文本字段

我正在使用Swift进行iOS编程,我正在使用此代码移动UITextField,但它不起作用.我keyboardWillShow正确调用该函数,但文本字段不移动.我正在使用autolayout.

override func viewDidLoad() {
    super.viewDidLoad()
    NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillShow:"), name:UIKeyboardWillShowNotification, object: nil);
    NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide:"), name:UIKeyboardWillHideNotification, object: nil);
}

deinit {
    NSNotificationCenter.defaultCenter().removeObserver(self);
}

func keyboardWillShow(notification: NSNotification) {
    if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {
        //let contentInsets = UIEdgeInsets(top: 0, left: 0, bottom: keyboardSize.height, right: 0)

        var frame = self.ChatField.frame
        frame.origin.y = frame.origin.y - keyboardSize.height + 167
        self.chatField.frame = frame
        println("asdasd")
    }
}
Run Code Online (Sandbox Code Playgroud)

keyboard cocoa-touch uitextfield ios swift

205
推荐指数
14
解决办法
19万
查看次数

UIScrollView按预期工作,但scrollRectToVisible:什么都不做

我以前用过UIScrollView,现在正在使用它,从来没有遇到过问题.我现在将它添加到一个旧的应用程序,虽然它按预期工作(我可以看看内容,用我的手指滚动,所有的边界和大小设置正确,所以内容中没有空白的空间,等等.),我只是无法scrollToRectVisible上班.我甚至简化了调用,以便它只移动到0,0位置:

 [scrollView scrollRectToVisible:CGRectMake(0, 0, 10, 10) animated:YES];
Run Code Online (Sandbox Code Playgroud)

或将其移至0,200:

 [scrollView scrollRectToVisible:CGRectMake(0, 200, 10, 10) animated:YES];
Run Code Online (Sandbox Code Playgroud)

我甚至做了一个快速的应用来测试这个,我可以scrollRectToVisible像我期望的那样去那里工作.但在我的旧应用程序中,我似乎无法做任何事情.

我可以使用scrollView滚动setContentOffset:,但这不是我想要的.

此scrollView及其内容由IB在nib中定义,并与IBOutlet一起使用.我在我的应用程序中使用的唯一代码来处理scrollView是

 [scrollView setContentSize:CGSizeMake(scrollView.contentSize.width, imageView.frame.size.height)];
Run Code Online (Sandbox Code Playgroud)

(我只对垂直滚动而不是水平感兴趣).

有没有人遇到这样的问题?

我比较了两个应用程序中的scrollView属性,它们是相同的.

附录:

我的scrollViews框架是:0.000000 0.000000 480.000000 179.000000

我的scrollViews contentSize是:0.000000 324.000000

它仍然像我想要滚动到的矩形已经可见,并且不需要滚动.不确定这是不是正在发生的事情.这只是最神奇的事情.似乎很容易解决这个问题......

附录#2:

这就是我没有做的事情scrollRectToVisible:

CGPoint point = myRect.origin;
if (![clefScrollView pointInside:point withEvent:nil]) {
    point.x = 0;
    if (point.y > clefScrollView.contentSize.height - clefScrollView.bounds.size.height)
        point.y = clefScrollView.contentSize.height - clefScrollView.bounds.size.height;
    [clefScrollView setContentOffset:point animated: YES];
}
Run Code Online (Sandbox Code Playgroud)

关于此scrollView的其他所有内容都按预期工作,但是scrollRectToVisible.为什么?!?任何疯狂的猜测?

iphone uiscrollview

61
推荐指数
3
解决办法
6万
查看次数

iOS"Gboard"应用,UIKeyboard通知高度错误或无效

当键盘弹出UITextfield放置在键盘上时,我正试图将视图向上移动UIScrollView.我使用的是UIKeyboardWillShowNotificationUIKeyboardWillHideNotification此.

iOS Keyboard我使用高度的地方时,它工作得很好297.

我的客户正在使用Gboard keyboard,他抱怨说观点不动.当我测试时,我的键盘高度为44.

我已经试过这两个键UIKeyboardFrameBeginUserInfoKeyUIKeyboardFrameEndUserInfoKeyNSNotifiction userInfo对象.两者44都只给予.

我试着用UIKeyboardDidShowNotificationUIKeyboardDidHideNotification也,还是同样的问题.

任何人都可以帮我这个..?

objective-c uikeyboard nsnotification ios

23
推荐指数
1
解决办法
571
查看次数

类型'NSNotification.Name'没有成员'keyboardDidShowNotification'

我用Swift 4.2得到了这个错误

类型'NSNotification.Name'没有成员'keyboardDidShowNotification'

这是我的代码:

NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardDidShow(notification:)), name: NSNotification.Name.keyboardDidShowNotification, object: nil)
Run Code Online (Sandbox Code Playgroud)

下面一个用Swift 4工作正常,但没有用Swift 4.2

NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardDidShow(notification:)), name: NSNotification.Name.UIKeyboardDidShow, object: nil)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Apple文档Ref:NSNotification.Name.keyboardDidShowNotification

keyboard-events nsnotificationcenter ios swift4.2

17
推荐指数
3
解决办法
2万
查看次数

Swift:ScrollRectToVisible无效

在尝试了这里发布的大多数解决方案后,我仍然无法移动文本字段以在滚动视图中显示在键盘上方.

这些是我从Stackoverflow解决方案中获得的链接 : 链接1 链接2 链接3

我正在进行一个注册屏幕,当它出现时,键盘后面有一个字段.

这是我的代码:

class SignUpViewController: UIViewController, UITextFieldDelegate, UIScrollViewDelegate, UIPopoverPresentationControllerDelegate {

@IBOutlet var firstNameTextField: UITextField!
@IBOutlet var lastNameTextField: UITextField!
@IBOutlet var phoneNumberTextField: UITextField!
@IBOutlet var emailTextField: UITextField!
@IBOutlet var submitButton: UIButton!
@IBOutlet var professionButton: UIButton!

var scrollView: UIScrollView?
var activeTextField:UITextField? = UITextField()

override func viewDidLoad() {
    super.viewDidLoad()

    let notificationCenter = NSNotificationCenter.defaultCenter()

    notificationCenter.addObserver(self, selector: #selector(SignUpViewController.keyboardWasShown(_:)), name: UIKeyboardWillShowNotification, object: nil)
    notificationCenter.addObserver(self, selector: #selector(SignUpViewController.keyboardWillBeHidden(_:)), name: UIKeyboardWillHideNotification, object: nil)
    scrollView = UIScrollView(frame: CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: …
Run Code Online (Sandbox Code Playgroud)

xcode uiscrollview ios swift

9
推荐指数
1
解决办法
5750
查看次数

textFieldDidBeginEditing过早调用

我有一个应用程序,我必须在键盘显示的情况下向上滚动.为了获得键盘大小,我正在注册UIKeyboardWillShowNotification事件,如下所示:

   [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(keyboardWillShow:)
     name:UIKeyboardWillShowNotification
     object:self.view.window]
Run Code Online (Sandbox Code Playgroud)

这确实有效,问题是,在调用textFieldDidBeginEditing之后调用它.因此,我无法获得实际的键盘大小,但只有在该字段已经处于编辑模式之后,这才会在首先注册此事件的整个目的.我确定我已经调用了UIKeyboardWillShowNotification而不是UIKeyboardDidShowNotification,尽管切换这两个产生了相同的结果:首先调用委托方法,然后调用通知方法.关于如何扭转局面的任何想法?目前我很难编码大小,这是非常糟糕的做法......

uitextfield autoscroll ios uitextfielddelegate

7
推荐指数
1
解决办法
2580
查看次数

当键盘覆盖 UITextView 时如何移动它

在此输入图像描述

UITextView当需要一些输入时,我需要将键盘移开。我正在使用以下代码,它与 a 完美配合,UITextField但与 a 则根本不起作用UITextView

override func viewDidLoad() {
    super.viewDidLoad()

    NSNotificationCenter.defaultCenter().addObserver(self,
                                                     selector: #selector(DailyNotesViewController.keyboardWillShow(_:)),
                                                     name: UIKeyboardWillShowNotification,
                                                     object: nil)
    NSNotificationCenter.defaultCenter().addObserver(self,
                                                     selector: #selector(DailyNotesViewController.keyboardWillHide(_:)),
                                                     name: UIKeyboardWillHideNotification,
                                                     object: nil)
}

deinit {
    NSNotificationCenter.defaultCenter().removeObserver(self)
}

func adjustInsetForKeyboardShow(show: Bool, notification: NSNotification) {
    let userInfo = notification.userInfo ?? [:]
    let keyboardFrame = (userInfo[UIKeyboardFrameBeginUserInfoKey] as! NSValue).CGRectValue()
    let adjustmentHeight = (CGRectGetHeight(keyboardFrame) + 20) * (show ? 1 : -1)
    scrollView.contentInset.bottom += adjustmentHeight
    scrollView.scrollIndicatorInsets.bottom += adjustmentHeight
}

func keyboardWillShow(notification: NSNotification) {
    adjustInsetForKeyboardShow(true, notification: notification)
}

func …
Run Code Online (Sandbox Code Playgroud)

uitextview ios swift

5
推荐指数
1
解决办法
1914
查看次数

键盘覆盖视图底部的文本字段

我搜索过了

here:仅当键盘覆盖输入字段时才向上移动视图

这里:当键盘快速显示时移动文本字段

这里:如何在键盘存在时使UITextField向上移动?

在这里:https://developer.apple.com/library/content/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html

不幸的是,所有链接和我能找到的其他地方似乎并没有提供我正在寻找的良好清洁解决方案.它们要么用Obj-c代码过时,要么在使用Swift 4Xcode 9的当前迭代中不能工作.

如何管理覆盖视图底部文本字段的键盘?我希望屏幕的视图只有当键盘覆盖文本字段视图时才会移动,而不使用滚动视图,能够对其进行动画处理以使其看起来很漂亮,而不是让它快速捕捉,最重要的是我不想使用外部图书馆.

来自Apple的CoreAnimation库非常棒,但是所有的示例代码都已过时,并且在目标c中已经过时了(我不相信Apple没有更新他们的文档).

如果有人能够指出我正确的方向更新和当前的代码或Apple的图书馆我错过了将专门解决这个问题,我将不胜感激.

keyboard view textfield ios swift

4
推荐指数
2
解决办法
1万
查看次数