//这个代码写在plist文件中
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<dict>
<key>CFBundleDevelopmentRegion</key>
en
<key>CFBundleDisplayName</key>
day2
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIcons</key>
<key>CFBundleIcons~ipad</key>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
6.0
<key>CFBundleName</key>
$(PRODUCT_NAME)
<key>CFBundlePackageType</key>
APPL
<key>CFBundleShortVersionString</key>
1.0
<key>CFBundleVersion</key>
1
<key>LSRequiresIPhoneOS</key>
<key>UIApplicationShortcutItems</key>
<key>UIApplicationShortcutItemIconType</key>
<string>UIApplicationShortcutIconTypeShare</string>
<key>UIApplicationShortcutItemTitle</key>
分享“DM3DTouch”
<key>UIApplicationShortcutItemType</key>
<string>cn.damon.DM3DTouchDemo.openShare</string>
<key>UIApplicationShortcutItemUserInfo</key>
key2
value2
<key>UIApplicationShortcutItemIconFile</key>
favorite
<key>UIApplicationShortcutItemTitle</key>
加关注
<key>UIApplicationShortcutItemType</key>
<string>cn.damon.DM3DTouchDemo.openfavorites</string>
<key>UIApplicationShortcutItemUserInfo</key>
key1
value1
<key>UILaunchStoryboardName</key>
LaunchScreen
<key>UIMainStoryboardFile</key>
Main
<key>UIRequiredDeviceCapabilities</key>
armv7
<key>UISupportedInterfaceOrientations</key>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</dict>
</plist>
写入方式
写入后,可以简单显示软件外围图标
效果图如下
开始写表格内容
//
#import "ViewController.h"
#import "ocViewController.h"
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>{
UITableView*table;
}
@property (nonatomic, strong)NSArray *arrData;
@end
@implementation ViewController
#pragma mark - 利用循环添加数组内容
- (NSArray*)arrData {
if(!_arrData) {
_arrData= [NSArrayarray];
NSMutableArray *arr = [NSMutableArray array];
for(inti =0; i <30; i++) {
[arraddObject:@(i)];
}
_arrData= arr;
}
return _arrData;
}
#pragma mark - 这是传值需要用到的东西
- (void)viewWillAppear:(BOOL)animated {
[superviewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:table selector:@selector(reloadData) name:@"NOTIFICATION_RELOADDATA" object:nil];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.title=@"发现";
table=[[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
table.dataSource=self;
table.delegate=self;
[self.view addSubview:table];
//这个代码可以让导航条更加舒适
self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
}
//返回表格列数
-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{
return self.arrData.count;
}
//表格内容
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
if(cell==nil) {
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
}
//添加表格的小图片
cell.accessoryType=UITableViewCellAccessoryCheckmark;
cell.contentView.backgroundColor = [UIColor whiteColor];
NSString *str = [NSString stringWithFormat:@"row [%@]", self.arrData[indexPath.row]];
cell.textLabel.text= str;
//////////
//这个代码必须要写,判断手机是否可以用3DTouch
if([selfrespondsToSelector:@selector(traitCollection)]) {
if([self.traitCollectionrespondsToSelector:@selector(forceTouchCapability)]) {
if (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable) {
[self registerForPreviewingWithDelegate:(id)self sourceView:cell];
}
}
}
//
returncell;
}
//代码必须要写,用来产生预览模式
- (nullableUIViewController*)previewingContext:(id)previewingContext viewControllerForLocation:(CGPoint)locationNS_AVAILABLE_IOS(9_0) {
NSIndexPath *indexPath = [table indexPathForCell:(UITableViewCell *)[previewingContext sourceView]];
NSString *str = [NSString stringWithFormat:@"%@",self.arrData[indexPath.row]];
//创建要预览的控制器
ocViewController *presentationVC = [[ocViewController alloc] init];
presentationVC.arrData= (NSMutableArray*)self.arrData;
presentationVC.index= indexPath.row;
presentationVC.strInfo= str;
//指定当前上下文视图Rect
CGRect rect = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 300);
previewingContext.sourceRect= rect;
returnpresentationVC;
}
#pragma mark pop(push)
- (void)previewingContext:(id)previewingContext commitViewController:(UIViewController*)viewControllerToCommitNS_AVAILABLE_IOS(9_0) {
[selfshowViewController:viewControllerToCommitsender:self];
}
- (void)viewWillDisappear:(BOOL)animated {
[[NSNotificationCenter defaultCenter] removeObserver:table name:@"NOTIFICATION_RELOADDATA" object:nil];
}
-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath{
[self.navigationController pushViewController:[ocViewController new] animated:YES];
}
@end
写完后的效果为
开始写另一个页面,我这边起名为ocviewcontroller
#import "ocViewController.h"
@interface ocViewController ()
@property (nonatomic, strong)UILabel *labInformation;
@end
@implementationocViewController
//这是预览的label,在预览页面显示用的
- (UILabel*)labInformation {
if (!_labInformation) {
_labInformation= [[UILabelalloc]init];
}
return _labInformation;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.title=@"二维码";
self.automaticallyAdjustsScrollViewInsets = NO;
self.view.backgroundColor = [UIColor whiteColor];
// [self configLabel];
}
//label内容
- (void)configLabel {
self.labInformation.text = [NSString stringWithFormat:@"通过点击下标为[%@]进来的", self.strInfo];
self.labInformation.textColor = [UIColor redColor];
self.labInformation.textAlignment = NSTextAlignmentCenter;
self.labInformation.frame=CGRectMake(0,0,200,30);
[self.labInformation sizeToFit];
CGPoint center = CGPointMake([UIScreen mainScreen].bounds.size.width/2, [UIScreen mainScreen].bounds.size.height/2);
self.labInformation.center= center;
[self.view addSubview:self.labInformation];
}
#pragma mark - 3D Touch 预览Action代理
- (NSArray> *)previewActionItems {
NSMutableArray *arrItem = [NSMutableArray array];
UIPreviewAction *previewAction0 = [UIPreviewAction actionWithTitle:@"取消" style:UIPreviewActionStyleDestructive handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
NSLog(@"didClickCancel");
}];
UIPreviewAction *previewAction1 = [UIPreviewAction actionWithTitle:@"替换该元素" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
//把下标为index的元素替换成preview
[selfreplaceItem];
}];
[arrItemaddObjectsFromArray:@[previewAction0 ,previewAction1]];
returnarrItem;
}
- (void)replaceItem {
if(self.arrData.count<=0)return;
[self.arrData replaceObjectAtIndex:self.index withObject:@"replace item"];
//发送通知更新数据
[[NSNotificationCenter defaultCenter] postNotificationName:@"NOTIFICATION_RELOADDATA" object:nil];
}
@end
写完后效果图为
如果想看详情以及demon可以去 https://www.jianshu.com/p/d472c6350a1a
这个大神里面有更加详情的内容。
网友评论