第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

選擇文本字段時生成UITableView滾動框

選擇文本字段時生成UITableView滾動框

iOS
富國滬深 2019-07-26 19:14:06
選擇文本字段時生成UITableView滾動框經(jīng)過多次嘗試和錯誤之后,我放棄了并問了這個問題。我見過很多人都有類似的問題,但無法找到正確的答案。我有一個UITableView由自定義單元格組成。單元格由相鄰的5個文本字段組成(有點像網(wǎng)格)。當(dāng)我試圖滾動和編輯底部的單元格時,UITableView,我無法使我的細(xì)胞正確地定位在鍵盤上方。我見過很多關(guān)于改變視野大小等問題的答案.但到目前為止,他們中沒有一個人工作得很好。有誰能用一個具體的代碼示例來澄清做這件事的“正確”方法嗎?
查看完整描述

3 回答

?
qq_花開花謝_0

TA貢獻(xiàn)1835條經(jīng)驗 獲得超7個贊

如果您使用UITableViewController而不是UIViewController,它將自動這樣做。



查看完整回答
反對 回復(fù) 2019-07-27
?
白板的微信

TA貢獻(xiàn)1883條經(jīng)驗 獲得超3個贊

進(jìn)行滾動的功能可能要簡單得多:

- (void) textFieldDidBeginEditing:(UITextField *)textField {
    UITableViewCell *cell;

    if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
    // Load resources for iOS 6.1 or earlier
        cell = (UITableViewCell *) textField.superview.superview;

    } else {
        // Load resources for iOS 7 or later
        cell = (UITableViewCell *) textField.superview.superview.superview; 
       // TextField -> UITableVieCellContentView -> (in iOS 7!)ScrollView -> Cell!
    }
    [tView scrollToRowAtIndexPath:[tView indexPathForCell:cell] atScrollPosition:UITableViewScrollPositionTop animated:YES];}

就這樣。根本沒有計算。




查看完整回答
反對 回復(fù) 2019-07-27
?
繁華開滿天機(jī)

TA貢獻(xiàn)1816條經(jīng)驗 獲得超4個贊

我正在做一些非常類似的事情-它是通用的,不需要為您的代碼計算特定的東西。只需檢查代碼上的注釋:

在MyUIViewController.h中

@interface MyUIViewController: UIViewController <UITableViewDelegate, UITableViewDataSource>{
     UITableView *myTableView;
     UITextField *actifText;}@property (nonatomic, retain) IBOutlet UITableView *myTableView;@property (nonatomic, retain) IBOutlet UITextField *actifText;- (IBAction)textFieldDidBeginEditing:(UITextField *)textField;- (IBAction)textFieldDidEndEditing:(UITextField *)textField;-(void) keyboardWillHide:(NSNotification *)note;-(void) keyboardWillShow:(NSNotification *)note;@end

在MyUIViewController.m中

@implementation MyUIViewController@synthesize myTableView;@synthesize actifText;- (void)viewDidLoad 
{
    // Register notification when the keyboard will be show
    [[NSNotificationCenter defaultCenter] addObserver:self
                                          selector:@selector(keyboardWillShow:)
                                          name:UIKeyboardWillShowNotification
                                          object:nil];

    // Register notification when the keyboard will be hide
    [[NSNotificationCenter defaultCenter] addObserver:self
                                          selector:@selector(keyboardWillHide:)
                                          name:UIKeyboardWillHideNotification
                                          object:nil];}// To be link with your TextField event "Editing Did Begin"//  memoryze the current TextField- (IBAction)textFieldDidBeginEditing:(UITextField *)textField{
    self.actifText = textField;}// To be link with your TextField event "Editing Did End"//  release current TextField- (IBAction)textFieldDidEndEditing:(UITextField *)textField{
    self.actifText = nil;}-(void) keyboardWillShow:(NSNotification *)note{
    // Get the keyboard size
    CGRect keyboardBounds;
    [[note.userInfo valueForKey:UIKeyboardFrameBeginUserInfoKey] getValue: &keyboardBounds];

    // Detect orientation
    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
    CGRect frame = self.myTableView.frame;

    // Start animation
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationDuration:0.3f];

    // Reduce size of the Table view 
    if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
        frame.size.height -= keyboardBounds.size.height;
    else 
        frame.size.height -= keyboardBounds.size.width;

    // Apply new size of table view
    self.myTableView.frame = frame;

    // Scroll the table view to see the TextField just above the keyboard
    if (self.actifText)
      {
        CGRect textFieldRect = [self.myTableView convertRect:self.actifText.bounds fromView:self.actifText];
        [self.myTableView scrollRectToVisible:textFieldRect animated:NO];
      }

    [UIView commitAnimations];}-(void) keyboardWillHide:(NSNotification *)note{
    // Get the keyboard size
    CGRect keyboardBounds;
    [[note.userInfo valueForKey:UIKeyboardFrameBeginUserInfoKey] getValue: &keyboardBounds];

    // Detect orientation
    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
    CGRect frame = self.myTableView.frame;

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationDuration:0.3f];

    // Increase size of the Table view 
    if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
        frame.size.height += keyboardBounds.size.height;
    else 
        frame.size.height += keyboardBounds.size.width;

    // Apply new size of table view
    self.myTableView.frame = frame;

    [UIView commitAnimations];}@end

SWIFT 1.2+版本:

class ViewController: UIViewController, UITextFieldDelegate {
    @IBOutlet weak var activeText: UITextField!
    @IBOutlet weak var tableView: UITableView!

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

    func textFieldDidBeginEditing(textField: UITextField) {
        activeText = textField    }

    func textFieldDidEndEditing(textField: UITextField) {
        activeText = nil
    }

    func keyboardWillShow(note: NSNotification) {
        if let keyboardSize = (note.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {
            var frame = tableView.frame            UIView.beginAnimations(nil, context: nil)
            UIView.setAnimationBeginsFromCurrentState(true)
            UIView.setAnimationDuration(0.3)
            frame.size.height -= keyboardSize.height
            tableView.frame = frame            if activeText != nil {
                let rect = tableView.convertRect(activeText.bounds, fromView: activeText)
                tableView.scrollRectToVisible(rect, animated: false)
            }
            UIView.commitAnimations()
        }
    }

    func keyboardWillHide(note: NSNotification) {
        if let keyboardSize = (note.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {
            var frame = tableView.frame            UIView.beginAnimations(nil, context: nil)
            UIView.setAnimationBeginsFromCurrentState(true)
            UIView.setAnimationDuration(0.3)
            frame.size.height += keyboardSize.height
            tableView.frame = frame            UIView.commitAnimations()
        }
    }}





查看完整回答
反對 回復(fù) 2019-07-27
  • 3 回答
  • 0 關(guān)注
  • 327 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號