IOS Swift uses Contentoffset to get your user registration page up and moving

Source: Internet
Author: User

In iOS

. h

  viewcontroller.h//  Use Contentoffset to make your user registration page move////  Created by Huang Quanhao on 15-1-4.//  Copyright (c) 2015 Huang Quanhao. All rights reserved.//#import <UIKit/UIKit.h> @interface viewcontroller:uiviewcontroller< Uitextfielddelegate> @property (Weak, nonatomic) Iboutlet Uiscrollview *scr; @property (weak, nonatomic) Iboutlet Uitextfield *fd1; @property (weak, nonatomic) Iboutlet Uitextfield *fd2; @property (weak, nonatomic) Iboutlet Uitextfield * FD3; @property (weak, nonatomic) Iboutlet Uitextfield *fd4; @property (weak, nonatomic) Iboutlet Uitextfield *fd5; @end

. m

viewcontroller.m//use Contentoffset to make your user registration page move////Created by Huang Quanhao on 15-1-4.//Copyright (c) 2015 Huang Quanhao. All rights reserved.//#import "ViewController.h" @interface Viewcontroller () @end @implementation viewcontroller-(void    ) Viewdidload {[Super viewdidload];    _fd1.delegate = self;    _fd2.delegate = self;    _fd3.delegate = self;    _fd4.delegate = self;    _fd5.delegate = self;    Additional setup after loading the view, typically from a nib. Follow the input box on our nib if you click then the pop-up keyboard will cover the input box, then we can use setcontentoffset this property to solve the problem}//when the keyboard will be entered to judge-(BOOL) Textfieldshouldbeginediting: (Uitextfield *) textfield{if (TextField = = _fd1) {[_scr Setcontentoffset:cgpointmak E (0, h) animated:yes];//so we let the sliding view bounce up the 40 height, then the keyboard cannot obscure the input box}else if (TextField = = _fd2) {[_SCR Setcontentoffset:    Cgpointmake (0, +) Animated:yes];    }else if (TextField = = _fd3) {[_scr setcontentoffset:cgpointmake (0, +) Animated:yes]; }else if (TextField = = _fd4) {[_scr setcOntentoffset:cgpointmake (0, Animated:yes)];    }else if (TextField = = _fd5) {[_scr setcontentoffset:cgpointmake (0) Animated:yes];    }//so we will make a view scrolling effect, the user experience is relatively good return YES; Remember to restore the _SCR when the keyboard is retracted//[_SCR setcontentoffset:cgpointmake (0, 0) animated:yes];}    -(void) didreceivememorywarning {[Super didreceivememorywarning]; Dispose of any resources the can be recreated.} @end

In Swift

viewcontroller.swift//use Contentoffset to make your user registration page move////Created by Huang Quanhao on 15-1-4.//Copyright (c) 2015 Huang Quanhao. All rights Reserved.//import Uikitclass Viewcontroller:uiviewcontroller,uitextfielddelegate {@IBOutlet weak var scr:    uiscrollview!    @IBOutlet weak var fd1:uitextfield!    @IBOutlet weak var fd2:uitextfield!    @IBOutlet weak var fd3:uitextfield!    @IBOutlet weak var fd4:uitextfield!        @IBOutlet weak var fd5:uitextfield! Override Func Viewdidload () {super.viewdidload ()//Do any additional setup after loading the view, typical                Ly from a nib.  Fd1.delegate = self Fd2.delegate = self Fd3.delegate = self Fd4.delegate = self Fd5.delegate =     Self//According to the input box on our nib if clicked then the pop-up keyboard will cover the input box, then we can use setcontentoffset this property to solve the problem}//textfidlddelegate Agent Func textfieldshouldbeginediting (Textfield:uitextfield), bool{if TextField = = fd1 {scr. setc Ontentoffset (CgpointmaKe (0, h), animated:true)//So we let the sliding view bounce up 40 of the height, then the keyboard cannot obscure the input box}else if TextField = = fd2 {scr. setcontent Offset (Cgpointmake (0, +), animated:true)}else if TextField = = fd3 {scr. Setcontentoffset (Cgpointmake (0, +), animated:true)}else if TextField = = fd4 {scr. Setcontentoffset (cgpointmake (0,), animate D:true)}else if TextField = = fd5 {scr. Setcontentoffset (cgpointmake (0,), Animated:true)}        This way we will make a view scrolling effect, the user experience is relatively good return true;    Remember to restore the _SCR when the keyboard is retracted//[_SCR setcontentoffset:cgpointmake (0, 0) Animated:yes]; } override func Didreceivememorywarning () {super.didreceivememorywarning ()//Dispose of any RESOURC    Es that can is recreated. }}



IOS Swift uses Contentoffset to get your user registration page up and moving

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.