IOS 3D Touch Features

Source: Internet
Author: User
Tags new set home screen

New Touch Experience--ios9 's 3D touchFirst, Introduction

After the advent of iphone6s, many of the fruit powders rushed to experience the extra dimension interaction that 3D touch brings to the user, a design called 3D touch, which, in principle, adds a sense of pressure that makes different user interactions by distinguishing between taps and presses.

second, learn and test 3D Touch on the simulator

3D Touch is a very new design, but Apple Docs has a message:

    • With Xcode 7.0 your must develop on a device that supports 3D Touch. Simulator in Xcode 7.0 does isn't support 3D Touch.

See this sentence heart is not half cold, yes, Xcode7 is supported by 3D touch development, but the simulator does not support this gesture, we can only learn and test on the real machine, but in the IT world, there is no shortage of people to save the world, Someone on GitHub has provided us with a plugin that allows us to test the effects of 3D touch on the simulator:

git address: https://github.com/DeskConnect/SBShortcutMenuSimulator.

attached. Sbshortcutmenusimulator Installation and use

In fact, the installation and use do not need to introduce, Git home page is very clear, here in the record again, only one point to note, if you like me, the computer is equipped with XCODE6 and Xcode7 two versions, the Xcode compilation path, need to make a change.

Installation:

Run the following command once in the terminal:

git clone Https://github.com/DeskConnect/SBShortcutMenuSimulator.gitcd Sbshortcutmenusimulatormake

If you have more than one version of Xcode in your computer, do the following first, and if you have only Xcode7, you can skip

sudo xcode-select-switch/applications/xcode2.app/contents/developer/

Note: The above command, Xcode2.app is your computer's Xcode name, here to pay special attention, if there are spaces in the name, need to modify, the space is removed, otherwise it will affect the execution of the command.

After that, perform the following actions in the Sbshortcutmenusimulator directory:

Xcrun simctl Spawn booted launchctl debug System/com.apple.springboard--environment dyld_insert_libraries= $PWD/ Sbshortcutmenusimulator.dylibxcrun simctl Spawn booted Launchctl stop Com.apple.SpringBoard

If there is no error, we can simulate the effect of 3D touch on the simulator by sending a message to the specified port:

echo ' com.apple.mobilecal ' | NC 127.0.0.1 8000

Where com.apple.mobilecal is the bundle ID of the app, if you want to test our app, change it to our app's Bundleid, the example application above is the system calendar, and you can see the effect of the emulator as follows:

three, 3D touch main applications

There are two main applications presented in this document:

    • 1.A user can now press your Home screens icon to immediately access functionality provided by your app.

    • 2.Within your app, a user can now press views to see previews of additional content and gain accelerated access to feature S.

The first part of the application is that we can go directly to the application's response function module via 3D gesture, on the Home Screen app icon. This feature, like our calendar example above, will show a menu next to the icon and click on the menu to access the corresponding function unit.

I personally understand that this feature, the push message feature plus the extended today feature of the iOS8 rollout, these three mechanisms make iOS apps incredibly flexible and user-friendly, without the time cost of looking for the ability to quickly use what they need.

The second part is an optimization of the app that allows users to preview some preloaded information on the view via 3D touch gestures, which makes the app more concise and interactive.

Four, 3D touch three major modules

The 3D touch feature in our app is mainly divided into the following three modules:

1. Home screen Quick Actions

Using the Home Screen app icon, we can use 3D touch to call out a menu, to quickly locate the Application function module related function development. such as the calendar above.

2. Peek and pop

This feature is a new set of user interaction mechanisms, with the following three phases of interaction in Viewcontroller when using 3D touch:

(1) The user is prompted to interact with the touch, which blurs the interactive controls around

(2) Continue deep Press, the preview view will appear

(3) Further interaction via interactive controls on the view

This module is designed to interact with the Web Page Preview on the URL connection.

3.Force Properties

IOS9 provides us with a new interactive parameter: Force. We can detect the intensity value of an interaction to do the corresponding interactive processing. For example, we can control the speed of fast forward, the speed of volume increase and so on.

v. Home screen Quick action using the relevant API

IOS9 provides us with two kinds of screen labels, static labels and dynamic tags, respectively.

1. Static label

A static label is a label that we configure in the configuration plist file of the project, which is available after the user installs the program, and the sort is preceded by a dynamic label.

Let's look at the configuration of the static tag first:

First of all, add the following key value in the Info.plist file (when I was testing, the system did not prompt, can only hand up):

An array of Uiapplicationshortcutitems is added first, and the elements added in this array are the corresponding static tags, and in each tag we need to add some key values for the setting:

Required (The following two key values must be set):

Uiapplicationshortcutitemtype This key value to set a shortcut channel type string

Uiapplicationshortcutitemtitle The title of this key value setting label

Optional (these key values are not required):

Uiapplicationshortcutitemsubtitle Setting the subtitle of a label

Uiapplicationshortcutitemicontype setting label icon type

Uiapplicationshortcutitemiconfile icon file for the Settings tab

Uiapplicationshortcutitemuserinfo setting information dictionary (for value transfer)

After we have set up, run the program, with our previous method to test, the effect is as follows:

2. Dynamic Label

Dynamic tagging is a class that we add to our program by code, with three main categories:

Uiapplicationshortcutitem Creating a 3DTouch tag class

Uimutableapplicationshortcutitem Creating a variable 3DTouch Label class

Uiapplicationshortcuticon create a class for a picture icon in a label

@interface  uiapplicationshortcutitem : nsobject <nscopying, nsmutablecopying>// Here are the two initialization methods   create a label by setting Type,title properties, here the icon is Uiapplicationshortcuticon object, we will say-  (Instancetype) Initwithtype: (nsstring *) Type localizedtitle: (nsstring *) Localizedtitle localizedsubtitle :(nullable nsstring *) Localizedsubtitle icon: (nullable uiapplicationshortcuticon *) Icon userinfo: (nullable nsdictionary *) userinfo ns_designated_initializer;-  ( Instancetype) Initwithtype: (nsstring *) Type localizedtitle: (nsstring *) localizedTitle;// Here are some read-only properties that get the corresponding property values @property  (nonatomic, copy, readonly)  NSString *type; @property   (nonatomic, copy, readonly)  NSString *localizedTitle; @property   (nullable,  nonatomic, copy, readonly)  NSString *localizedSubtitle; @property   (nullable,  Nonatomic, copy, readonly)  uiapplicationshortcuticon *icon; @property   (nullable, nonatomic, copy, readonly)   nsdictionary<nsstring *, id <nssecurecoding>> *userinfo;
This class creates a label [email protected] uiapplicationshortcuticon:nsobject <nscopying>//Create a system-style icon+ (instancetype) Iconwithtype: (uiapplicationshortcuticontype) type;//Create a custom picture icon+ (Instancetype) Iconwithtemplateimagename: ( NSString *) Templateimagename; @end

Once you have created the tag, add it as a hortcutitems array of application, as shown in the following example:

-(void) viewdidload {[Super viewdidload];  Additional setup after loading the view, typically from a nib. Create Uiapplicationshortcutitem * item = [[Uiapplicationshortcutitem alloc]initwithtype:@ "Two" localizedtitle:@ "second label" localizedsubtitle:@ "See Me," Icon:[uiapplicationshortcuticon Iconwithtype:uiapplicationshortcuticontypeplay] UserInfo  : nil]; add [UIApplication sharedapplication].shortcutitems = @[item];}

The effect is as follows:

Here, the enumeration of system style icons is listed below:

typedef ns_enum (Nsinteger, Uiapplicationshortcuticontype) {uiapplicationshortcuticontypecompose,//edit icon  uiapplicationshortcuticontypeplay,//Play icon uiapplicationshortcuticontypepause,//pause icon  uiapplicationshortcuticontypeadd,//Add icon uiapplicationshortcuticontypelocation,//positioning icon uiapplicationshortcuticontypesearch,//Search icon uiapplicationshortcuticontypeshare//share icon} ns_enum_available_ios (9_0);
3. Response tag Behavior

Similar push, when we click on the tag to enter the application, we can also do some actions, we can see, in the Applocation added a method:

-(void) Application: ( UIApplication *) Application Performactionforshortcutitem: (Uiapplicationshortcutitem *) ShortcutItem Completionhandler: (void (^) (boolsucceeded)) Completionhandler Ns_available_ios (9 _0);

When we enter the app through a tag, we call such a callback in Appdelegate, and we can get the Shortcutitem information for the relevant logical operation.

Here's one thing to note: Our entry function in the app:

-(BOOL) Application: ( UIApplication *) Application didfinishlaunchingwithoptions: ( Nsdictionary *) launchoptions;

Also need to make a judgment, in Launchoptions has uiapplicationlaunchoptionsshortcutitemkey such a key, through it, we can distinguish whether the app is entered from the tag, if it is the end logic processing, Returns no to prevent the processing logic from being repeatedly recalled.

Some notes:

1, the shortcut tag can create up to four, including static and dynamic.

2, the title of each label and icon at most two lines, the more will be used ... Omitted

Vi. Conclusion

About 3DTouch in UIView preview function and the application of the new force attribute in the Uitouch, because not good presentation, here is no longer summarized, you can use the corresponding class and attributes in the header file to understand them, and finally, if there are omissions and errors, please correct.

Transferred from: Http://my.oschina.net/SoulJa/blog/525680?fromerr=Uof9QqBD

IOS 3D Touch Features

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.