[Turn]3d Touch

Source: Internet
Author: User
Tags home screen

IOS9 's 3D Touch

First, 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.git

CD Sbshortcutmenusimulator

Make

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.dylib

Xcrun 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

Because these classes are newly added classes in IOS9, their APIs are not very complex, so let's briefly explain the methods and properties:

@interface Uiapplicationshortcutitem:nsobject <nscopying, nsmutablecopying>

Here are two initialization methods to create a label by setting Type,title properties, and here the icon is the Uiapplicationshortcuticon object, we'll talk about it later.

-(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 inherits from the Uiapplicationshortcutitem, creating a variable label

@interface Uimutableapplicationshortcutitem:uiapplicationshortcutitem

@property (nonatomic, copy) NSString *type;

@property (nonatomic, copy) NSString *localizedtitle;

@property (nullable, nonatomic, copy) NSString *localizedsubtitle;

@property (nullable, nonatomic, copy) Uiapplicationshortcuticon *icon;

@property (nullable, nonatomic, copy) nsdictionary<nsstring *, id <NSSecureCoding>> *userinfo;

@end

This class creates the icon in the tag

@interface Uiapplicationshortcuticon:nsobject <NSCopying>

Create a system-style icon

+ (Instancetype) Iconwithtype: (uiapplicationshortcuticontype) type;

Creating 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 to

[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 (^) (BOOL succeeded)) 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

[Turn]3d Touch

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.