Skip to content

Commit 67e34de

Browse files
author
yangdongwu
committed
1-添加icon上的快捷按钮2-添加预览视图
1 parent 2d64596 commit 67e34de

File tree

17 files changed

+1212
-0
lines changed

17 files changed

+1212
-0
lines changed

DYShortcutItemDemo/DYShortcutItemDemo.xcodeproj/project.pbxproj

Lines changed: 542 additions & 0 deletions
Large diffs are not rendered by default.

DYShortcutItemDemo/DYShortcutItemDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// AppDelegate.h
3+
// DYShortcutItemDemo
4+
//
5+
// Created by DovYoung on 2017/1/19.
6+
// Copyright © 2017年 DovYoung. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
@interface AppDelegate : UIResponder <UIApplicationDelegate>
12+
13+
@property (strong, nonatomic) UIWindow *window;
14+
15+
16+
@end
17+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//
2+
// AppDelegate.m
3+
// DYShortcutItemDemo
4+
//
5+
// Created by DovYoung on 2017/1/19.
6+
// Copyright © 2017年 DovYoung. All rights reserved.
7+
//
8+
9+
#import "AppDelegate.h"
10+
11+
@interface AppDelegate ()
12+
13+
@end
14+
15+
@implementation AppDelegate
16+
17+
18+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
19+
20+
[self addShortcutItems];
21+
22+
return YES;
23+
}
24+
25+
- (void)addShortcutItems {
26+
27+
UIApplicationShortcutIcon *icon1 = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeCompose];
28+
29+
UIApplicationShortcutIcon *icon2 = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypePlay];
30+
31+
UIApplicationShortcutIcon *icon3 = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeAdd];
32+
33+
UIMutableApplicationShortcutItem *item1 = [[UIMutableApplicationShortcutItem alloc] initWithType:@"com.test.dynamic" localizedTitle:@"item1" localizedSubtitle:@"item1sub" icon:icon1 userInfo:nil];
34+
35+
UIMutableApplicationShortcutItem *item2 = [[UIMutableApplicationShortcutItem alloc] initWithType:@"com.test.dynamic" localizedTitle:@"item2" localizedSubtitle:@"item2sub" icon:icon2 userInfo:nil];
36+
37+
UIMutableApplicationShortcutItem *item3 = [[UIMutableApplicationShortcutItem alloc] initWithType:@"com.test.dynamic" localizedTitle:@"item3" localizedSubtitle:@"item3sub" icon:icon3 userInfo:nil];
38+
39+
NSArray *items = @[item1, item2, item3];
40+
if ([UIApplication sharedApplication].shortcutItems.count == 0) {
41+
42+
[UIApplication sharedApplication].shortcutItems = items;
43+
44+
}
45+
46+
}
47+
48+
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler {
49+
50+
NSLog(@"%@",shortcutItem.localizedTitle);
51+
52+
}
53+
54+
@end
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "iphone",
5+
"size" : "29x29",
6+
"scale" : "2x"
7+
},
8+
{
9+
"idiom" : "iphone",
10+
"size" : "29x29",
11+
"scale" : "3x"
12+
},
13+
{
14+
"idiom" : "iphone",
15+
"size" : "40x40",
16+
"scale" : "2x"
17+
},
18+
{
19+
"idiom" : "iphone",
20+
"size" : "40x40",
21+
"scale" : "3x"
22+
},
23+
{
24+
"idiom" : "iphone",
25+
"size" : "60x60",
26+
"scale" : "2x"
27+
},
28+
{
29+
"idiom" : "iphone",
30+
"size" : "60x60",
31+
"scale" : "3x"
32+
},
33+
{
34+
"idiom" : "ipad",
35+
"size" : "29x29",
36+
"scale" : "1x"
37+
},
38+
{
39+
"idiom" : "ipad",
40+
"size" : "29x29",
41+
"scale" : "2x"
42+
},
43+
{
44+
"idiom" : "ipad",
45+
"size" : "40x40",
46+
"scale" : "1x"
47+
},
48+
{
49+
"idiom" : "ipad",
50+
"size" : "40x40",
51+
"scale" : "2x"
52+
},
53+
{
54+
"idiom" : "ipad",
55+
"size" : "76x76",
56+
"scale" : "1x"
57+
},
58+
{
59+
"idiom" : "ipad",
60+
"size" : "76x76",
61+
"scale" : "2x"
62+
}
63+
],
64+
"info" : {
65+
"version" : 1,
66+
"author" : "xcode"
67+
}
68+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11134" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
3+
<dependencies>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11106"/>
5+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
6+
</dependencies>
7+
<scenes>
8+
<!--View Controller-->
9+
<scene sceneID="EHf-IW-A2E">
10+
<objects>
11+
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
12+
<layoutGuides>
13+
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
14+
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
15+
</layoutGuides>
16+
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
17+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
18+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
19+
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
20+
</view>
21+
</viewController>
22+
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
23+
</objects>
24+
<point key="canvasLocation" x="53" y="375"/>
25+
</scene>
26+
</scenes>
27+
</document>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16A323" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="Rpc-k5-34Q">
3+
<device id="retina4_7" orientation="portrait">
4+
<adaptation id="fullscreen"/>
5+
</device>
6+
<dependencies>
7+
<deployment identifier="iOS"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
9+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
10+
</dependencies>
11+
<scenes>
12+
<!--main-->
13+
<scene sceneID="tne-QT-ifu">
14+
<objects>
15+
<viewController id="BYZ-38-t0r" customClass="ViewController" sceneMemberID="viewController">
16+
<layoutGuides>
17+
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
18+
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
19+
</layoutGuides>
20+
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
21+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
22+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
23+
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
24+
</view>
25+
<navigationItem key="navigationItem" title="main" id="Ara-0P-PNj"/>
26+
</viewController>
27+
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
28+
</objects>
29+
<point key="canvasLocation" x="1076" y="115.59220389805098"/>
30+
</scene>
31+
<!--Navigation Controller-->
32+
<scene sceneID="208-gN-WV3">
33+
<objects>
34+
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="Rpc-k5-34Q" sceneMemberID="viewController">
35+
<toolbarItems/>
36+
<navigationBar key="navigationBar" contentMode="scaleToFill" id="5Lp-ed-eHe">
37+
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
38+
<autoresizingMask key="autoresizingMask"/>
39+
</navigationBar>
40+
<nil name="viewControllers"/>
41+
<connections>
42+
<segue destination="BYZ-38-t0r" kind="relationship" relationship="rootViewController" id="jDe-pv-DfG"/>
43+
</connections>
44+
</navigationController>
45+
<placeholder placeholderIdentifier="IBFirstResponder" id="v3G-o2-T4m" userLabel="First Responder" sceneMemberID="firstResponder"/>
46+
</objects>
47+
<point key="canvasLocation" x="140" y="-567.16641679160421"/>
48+
</scene>
49+
</scenes>
50+
</document>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>NSAppTransportSecurity</key>
6+
<dict>
7+
<key>NSAllowsArbitraryLoads</key>
8+
<true/>
9+
</dict>
10+
<key>UIApplicationShortcutItems</key>
11+
<array>
12+
<dict>
13+
<key>UIApplicationShortcutType</key>
14+
<string>com.test.static1</string>
15+
<key>UIApplicationShortcutItemTitle</key>
16+
<string>Static Shortcut</string>
17+
<key>UIApplicationShortcutItemSubtitle</key>
18+
<string>available at lunch</string>
19+
<key>UIApplicationShortcutItemIconFile</key>
20+
<string>iCon1</string>
21+
</dict>
22+
</array>
23+
<key>CFBundleDevelopmentRegion</key>
24+
<string>en</string>
25+
<key>CFBundleExecutable</key>
26+
<string>$(EXECUTABLE_NAME)</string>
27+
<key>CFBundleIdentifier</key>
28+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
29+
<key>CFBundleInfoDictionaryVersion</key>
30+
<string>6.0</string>
31+
<key>CFBundleName</key>
32+
<string>$(PRODUCT_NAME)</string>
33+
<key>CFBundlePackageType</key>
34+
<string>APPL</string>
35+
<key>CFBundleShortVersionString</key>
36+
<string>1.0</string>
37+
<key>CFBundleVersion</key>
38+
<string>1</string>
39+
<key>LSRequiresIPhoneOS</key>
40+
<true/>
41+
<key>UILaunchStoryboardName</key>
42+
<string>LaunchScreen</string>
43+
<key>UIMainStoryboardFile</key>
44+
<string>Main</string>
45+
<key>UIRequiredDeviceCapabilities</key>
46+
<array>
47+
<string>armv7</string>
48+
</array>
49+
<key>UISupportedInterfaceOrientations</key>
50+
<array>
51+
<string>UIInterfaceOrientationPortrait</string>
52+
<string>UIInterfaceOrientationLandscapeLeft</string>
53+
<string>UIInterfaceOrientationLandscapeRight</string>
54+
</array>
55+
<key>UISupportedInterfaceOrientations~ipad</key>
56+
<array>
57+
<string>UIInterfaceOrientationPortrait</string>
58+
<string>UIInterfaceOrientationPortraitUpsideDown</string>
59+
<string>UIInterfaceOrientationLandscapeLeft</string>
60+
<string>UIInterfaceOrientationLandscapeRight</string>
61+
</array>
62+
</dict>
63+
</plist>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// PreviewingViewController.h
3+
// DYShortcutItemDemo
4+
//
5+
// Created by DovYoung on 2017/1/20.
6+
// Copyright © 2017年 DovYoung. All rights reserved.
7+
//
8+
9+
#import "ViewController.h"
10+
11+
@interface PreviewingViewController : UIViewController
12+
13+
@end
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//
2+
// PreviewingViewController.m
3+
// DYShortcutItemDemo
4+
//
5+
// Created by DovYoung on 2017/1/20.
6+
// Copyright © 2017年 DovYoung. All rights reserved.
7+
//
8+
9+
#import "PreviewingViewController.h"
10+
#import "ViewController.h"
11+
12+
@interface PreviewingViewController () <UIViewControllerPreviewingDelegate>
13+
14+
@end
15+
16+
@implementation PreviewingViewController
17+
18+
- (void)viewDidLoad {
19+
[super viewDidLoad];
20+
21+
self.automaticallyAdjustsScrollViewInsets = NO;
22+
23+
self.view.backgroundColor = [UIColor redColor];
24+
25+
self.navigationItem.title = @"previewing";
26+
27+
}
28+
29+
#pragma mark - UIViewControllerPreviewingDelegate
30+
31+
- (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location {
32+
33+
NSLog(@"%s", __FUNCTION__);
34+
35+
NSLog(@"%@\n%@",previewingContext,NSStringFromCGPoint(location));
36+
37+
ViewController *preview = [[ViewController alloc] init];
38+
39+
return preview;
40+
41+
}
42+
43+
- (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit {
44+
45+
NSLog(@"%s", __FUNCTION__);
46+
47+
}
48+
49+
#pragma mark - 重写预览选项
50+
- (NSArray<id<UIPreviewActionItem>> *)previewActionItems {
51+
52+
UIPreviewAction *action1 = [UIPreviewAction actionWithTitle:@"Action 1" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
53+
54+
NSLog(@"Action 1 triggered");
55+
56+
}];
57+
58+
return @[action1];
59+
60+
}
61+
62+
@end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// ViewController.h
3+
// DYShortcutItemDemo
4+
//
5+
// Created by DovYoung on 2017/1/19.
6+
// Copyright © 2017年 DovYoung. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
@interface ViewController : UIViewController
12+
13+
14+
@end
15+

0 commit comments

Comments
 (0)