-6

I have a problem with my app, look at this pic

this pic

Now I'm typing on textView , I want a way to resize the textview or move it to top or scrolling to the last where I'm typing please help

I saw many answers here but all not working with me , and this is the code when i tried one of the answers

import UIKit

class AddEditClassNoteViewController: UIViewController {

    @IBOutlet var keyboardHeightLayoutConstraint: NSLayoutConstraint?


    override func viewDidLoad() {
        super.viewDidLoad()


        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


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

    @IBOutlet weak var noteTextBox: UITextView!

    override func touchesBegan(touches: NSSet, withEvent event: UIEvent)
    {

   self.noteTextBox.resignFirstResponder()




    }





        func textFieldDidBeginEditing(textField: UITextField) {
            animateViewMoving(true,moveValue: 100)
        }
        func textFieldDidEndEditing(textField: UITextField) {
            animateViewMoving(false,moveValue: 100)
        }

    func animateViewMoving (up:Bool, moveValue :CGFloat){
        var movementDuration:NSTimeInterval = 0.3
        var movement:CGFloat = ( up ? -moveValue : moveValue)
        UIView.beginAnimations( "animateView", context: nil)
        UIView.setAnimationBeginsFromCurrentState(true)
        UIView.setAnimationDuration(movementDuration )
        self.view.frame = CGRectOffset(self.view.frame, 0,  movement)
        UIView.commitAnimations()
    }






}

Im using Swift IOS 8

IOS Geek
  • 1
  • 3
  • The code you posted doesn't do anything meaningful. Please post something more or consider using one of many third party tools that accomplish the same thing. – InkGolem Feb 11 '15 at 18:33
  • i don't know how i do this things that's why I'm trying to find out how , if you have any third party tool give me , thanks – IOS Geek Feb 11 '15 at 18:34
  • Your question is really too big for a simple answer. Consider using (or building off of) a third party solution like that provided by the creators of [Slack (download here)](https://github.com/slackhq/SlackTextViewController). – InkGolem Feb 11 '15 at 18:37
  • Thanks for answer , i don't know did you feel my question is bad ? i don't know why people here voting my question as bad ! . – IOS Geek Feb 11 '15 at 18:39

2 Answers2

0

It seems like you're asking for several things, (all of which, I'm guessing, already have answers on Stack Overflow) but I'll do my best to give you a few examples.

First, what you have so far seems to hide the keyboard when you tap on the view. That may be partially defeating your purpose.

Second, if you're trying to scroll to the top of the your noteTextBox, try using: noteTextBox.setContentOffset(CGPointMake(0, 0), animated: true)
[Use animted: true if you want a scrolling animation. You may not, I don't know]

Third, check out this question for resizing the UITextView: Click Here

Fourth, check out this question for returning to a "remembered" position on your UIView: Click Here

Good luck,
Kyle

Community
  • 1
  • 1
kbpontius
  • 3,867
  • 1
  • 30
  • 34
  • thank you i will check and try now , if you have any cocopods library doing this things pls placed here – IOS Geek Feb 11 '15 at 18:41
  • I don't have a CocoaPods library for this, however the code should be fairly easy to implement. I recommend breaking down your question into smaller chunks like "How do I scroll to the top of a UITextView?" or "How do I adjust the size of a UITextView?". This will make it easier to find answers to those questions you have. – kbpontius Feb 11 '15 at 18:45
0

for any one need the answer with Swift language , The answer is as following simple change only .

import UIKit

class AddEditClassNoteViewController: UIViewController {

    var keyboardShowing = false
    @IBOutlet weak var noteTextBox: UITextView!


    override func viewDidLoad() {
        super.viewDidLoad()
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardShow:", name: UIKeyboardWillShowNotification, object: nil)
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardHide:", name: UIKeyboardWillHideNotification, object: nil)


        // Do any additional setup after loading the view.
    }
    override func shouldAutorotate() -> Bool {
        return !self.keyboardShowing
    }

    // much simpler than in iOS 7; a lot of the touchy bugs are gone in iOS 8
    // as long as you play your part (adjust content offset),
    // iOS 8 will play its part (scroll cursor to visible)
    // and we don't have to animate




    func keyboardShow(n:NSNotification) {
        self.keyboardShowing = true

        let d = n.userInfo!
        var r = (d[UIKeyboardFrameEndUserInfoKey] as NSValue).CGRectValue()
        r = self.noteTextBox.convertRect(r, fromView:nil)
        self.noteTextBox.contentInset.bottom = r.size.height
        self.noteTextBox.scrollIndicatorInsets.bottom = r.size.height
    }

    func keyboardHide(n:NSNotification) {
        self.keyboardShowing = false
        self.noteTextBox.contentInset = UIEdgeInsetsZero
        self.noteTextBox.scrollIndicatorInsets = UIEdgeInsetsZero
    }

    func doDone(sender:AnyObject) {
        self.view.endEditing(false)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


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


    override func touchesBegan(touches: NSSet, withEvent event: UIEvent)
    {

   self.noteTextBox.resignFirstResponder()




    }







}

Thanks for all who was trying to helping me .

IOS Geek
  • 1
  • 3