3D touch_helloworld_junyang的博客-程序员秘密

技术标签: 移动开发  

#import "BSTableViewController.h"

#import "BSDetailViewController.h"



@interface BSTableViewController ()<</span>UIViewControllerPreviewingDelegate,BSDetailViewControllerDelegate>


@property (nonatomic,strong)NSMutableArray *items;

@property (nonatomic,weak)UITableViewCell *selectedCell;


@end


@implementation BSTableViewController


- (NSMutableArray *)items {

    if (!_items) {

        _items = [[NSMutableArray alloc]initWithObjects:@"one",@"two",@"three",@"four",@"five",@"six",@"seven",@"eight",nil];

    }

    return _items;

}



- (void)viewDidLoad {

    [super viewDidLoad];

    

//    self.tableView.backgroundColor = [UIColor greenColor];

    self.title = @"3DTouchDemo";

    self.tableView.rowHeight = 100;

    // 重要

   

    [self registerForPreviewingWithDelegate:self sourceView:self.view];

}


#pragma mark - UIViewControllerPreviewingDelegate


- (UIViewController *)previewingContext:(id<<span style="font-variant-ligatures: no-common-ligatures; color: #703daa">UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location {

    

    NSIndexPath *indexPath = [self.tableView indexPathForCell:(UITableViewCell* )[previewingContext sourceView]];

//    NSLog(@"---%d",indexPath.row);

    

    

//    self.selectedCell = [self searchCellWithPoint:location];

//    previewingContext.sourceRect = self.selectedCell.frame;

    BSDetailViewController *detailVC = [[BSDetailViewController alloc] init];

    detailVC.delegate = self;

    detailVC.navTitle = self.selectedCell.textLabel.text;

    return detailVC;

}


- (void)previewingContext:(id<<span style="font-variant-ligatures: no-common-ligatures; color: #703daa">UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit {

    NSLog(@"fads");

    [self tableView:self.tableView didSelectRowAtIndexPath:[self.tableViewindexPathForCell:self.selectedCell]];

}


// 根据一个点寻找对应cell并返回cell

- (UITableViewCell *)searchCellWithPoint:(CGPoint)point {

    UITableViewCell *cell = nil;

    for (UIView *view in self.tableView.subviews) {

        NSString *class = [NSString stringWithFormat:@"%@",view.class];

        if (![class isEqualToString:@"UITableViewWrapperView"]) continue;

        for (UIView *tempView in view.subviews) {

            if ([tempView isKindOfClass:[UITableViewCell class]] && CGRectContainsPoint(tempView.frame, point)) {

                cell = (UITableViewCell *)tempView;

                break;

            }

        }

        break;

    }

    return cell;

}


#pragma mark - BSDetailViewControllerDelegate

- (void)detailViewControllerDidSelectedBackItem:(BSDetailViewController*)detailVC {

    NSLog(@"back");

}


- (void)detailViewController:(BSDetailViewController *)detailVC DidSelectedDeleteItem:(NSString *)navTitle {

    [self.items removeObject:navTitle];

    [self.tableView reloadData];

}

#pragma mark - Table view data source


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.items.count;

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *ID = @"cellid";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];

    if (!cell) {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];

//        [self registerForPreviewingWithDelegate:self sourceView:cell];

    }

    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    

    cell.textLabel.text = self.items[indexPath.row];

    cell.detailTextLabel.text = [NSString stringWithFormat:@"%zd",indexPath.row + 1];

    

    return cell;

}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath {

    

    

    BSDetailViewController *detailVC = [[BSDetailViewController alloc] init];

    detailVC.navTitle = self.items[indexPath.row];

    

    [self.navigationController pushViewController:detailVC animated:YES];

}


@end


// 版权属于原作者

// http://code4app.com (cn) http://code4app.net (en)

// 发布代码于最专业的源码分享网站: Code4App.com





//

//  BSDetailViewController.h

//  3DTouchDemo

//

//  Created by roki on 16/1/26.

//  Copyright 2016 roki. All rights reserved.

//


#import

@class BSDetailViewController;


@protocol BSDetailViewControllerDelegate <<span style="font-variant-ligatures: no-common-ligatures; color: #703daa">NSObject>


@required

// 删除按钮点击

- (void)detailViewController:(BSDetailViewController *)detailVC DidSelectedDeleteItem:(NSString *)navTitle;

// 返回按钮点击

- (void)detailViewControllerDidSelectedBackItem:(BSDetailViewController*)detailVC;


@end


@interface BSDetailViewController : UIViewController


@property (nonatomic,copy)NSString *navTitle;


@property (nonatomic,weak)id<</span>BSDetailViewControllerDelegate> delegate;


@end

// 版权属于原作者

// http://code4app.com (cn) http://code4app.net (en)

 

// 发布代码于最专业的源码分享网站: Code4App.com






//

//  BSDetailViewController.m

//  3DTouchDemo

//

//  Created by roki on 16/1/26.

//  Copyright 2016 roki. All rights reserved.

//


#import "BSDetailViewController.h"


@interface BSDetailViewController ()


@end


@implementation BSDetailViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];

    self.title = self.navTitle;

    UIImageView *imageView = [[UIImageView allocinitWithFrame:CGRectMake(86,100200150)];

    imageView.image = [UIImage imageNamed:@"imageone"];

    UILabel *githubName = [[UILabel allocinit];

    githubName.text = @"ITBigSea";

    githubName.textColor = [UIColor blueColor];

    githubName.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9alpha:1];

    githubName.frame = CGRectMake(13627010030);

    githubName.textAlignment = NSTextAlignmentCenter;

    

    [self.view addSubview:imageView];

    [self.view addSubview:githubName];

}


- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


- (NSArray<<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2">id<<span style="font-variant-ligatures: no-common-ligatures; color: #703daa">UIPreviewActionItem>> *)previewActionItems {

    //

    UIPreviewAction *action1 = [UIPreviewAction actionWithTitle:@"删除"style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {

        if ([self.delegaterespondsToSelector:@selector(detailViewController:DidSelectedDeleteItem:)]) {

            [self.delegate detailViewController:selfDidSelectedDeleteItem:self.navTitle];

        }

    }];

    //

    UIPreviewAction *action2 = [UIPreviewAction actionWithTitle:@"返回"style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {

        if ([self.delegate respondsToSelector:@selector(detailViewControllerDidSelectedBackItem:)]) {

            [self.delegate detailViewControllerDidSelectedBackItem:self];

        }

    }];

    

    NSArray *actions = @[action1,action2];

    

    return actions;

}

@end



如果添加图标上的3d touch

则在appdelegate中添加如下代码


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.

    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

    

    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[[BSTableViewController alloc] init]];

    

    self.window.rootViewController = nav;

    

    // 动态添加快捷启动

    UIApplicationShortcutIcon *icon = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeAlarm];

    UIApplicationShortcutItem *item = [[UIApplicationShortcutItem alloc] initWithType:@"shortcutTypeTwo" localizedTitle:@"two" localizedSubtitle:nil icon:icon userInfo:nil];

    [[UIApplication sharedApplication] setShortcutItems:@[item]];

    

    

    [self.window makeKeyAndVisible];

    return YES;

}


这是新增添的方法

- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler {

    

    UINavigationController *nav = (UINavigationController *)self.window.rootViewController;

    BSDetailViewController *detailVC = [[BSDetailViewController alloc] init];

    

    if ([shortcutItem.type isEqualToString:@"shortcutTypeOne"]) {

        detailVC.navTitle = @"one";

        

    } else if ([shortcutItem.type isEqualToString:@"shortcutTypeTwo"]) {

        detailVC.navTitle = @"two";

    }

    

    [nav pushViewController:detailVC animated:YES];

}



版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/helloworld_junyang/article/details/51023069

智能推荐

列表介绍,循环遍历,相关操作,嵌套_PG_peng丶的博客-程序员秘密

列表介绍想一想:前面学习的字符串可以用来存储一串信息,那么想一想,怎样存储咱们班所有同学的名字呢?定义100个变量,每个变量存放一个学生的姓名可行吗?有更好的办法吗?答:列表&amp;lt;1&amp;gt;列表的格式变量A的类型为列表namesList = ['xiaoWang','xiaoZhang','xiaoHua']比C语言的数组强大的地方在于列表中的元素可以是不同类型的testL...

‘Tensor‘ object has no attribute ‘numpy‘处理方法_agoodboy1997的博客-程序员秘密

在实现多层感知机的时候import tensorflow as tfimport numpy as np#实现一个简单的DataLoader类来读取MNIST数据集数据class DataLoader(): def __init__(self): mnist = tf.contrib.learn.datasets.load_dataset("mnist") ...

Oracle 字符集问题_weixin_30725467的博客-程序员秘密

1 简介 ORACLE数据库字符集,即Oracle全球化支持(Globalization Support),或即国家语言支持(NLS)其作用是用本国语言和格式来存储、处理和检索数据。利用全球化支持,ORACLE为用户提供自己熟悉的数据库母语环境,诸如日期格式、数字格式和存储序列等。Oracle可以支持多种语言及字符集,其中oracle8i支持48种语言、76个国家地域、229种字符集,而oracl...

Nginx系列教程(08) - Upstream Server 负载均衡_杨林伟的博客-程序员秘密

1.Upstream Server简介Upstream Server 中文翻译上游服务器,意思就是负载均衡服务器设置,白话文表示(就是被nginx代理最后真实访问的服务器)。负载均衡算法:配置多个上游服务器(真实业务逻辑访问的服务器)的负载均衡机制。失败重试机制:当上游服务器出现超时或者服务器不存活,是否考虑重试机制(补偿机制)。服务器心跳检测: 上游服务器监控检测、心跳检测。...

EditText获取焦点的一系列方法_after_leaving的博客-程序员秘密

/** * Set whether this view can receive the focus. * * Setting this to false will also ensure that this view is not focusable * in touch mode. * * @param focusable If true, this view can re

设计模式——迭代器模式_呼噜噜哟的博客-程序员秘密

设计模式:迭代器模式一、前言 设计模式有很多,最典型的是GoF的23种设计模式,听起来很多,其实大部分我们都是见过的,按照常见度来分,最常用的差不多是六七个吧,因此,我们在学习的时候应该有轻重缓急之分,不能一视同仁,而应该抓住重点,将一些最常用的设计模式吃透了,那么我们在遇到一个实际问题的时候就能根据问题的需要来进行相应的取舍。学习是一个循环往复的过程,没有学过一次不再接触就能掌握的,一...

随便推点

krpano-tools去水印_IT-hero的博客-程序员秘密

其实我也没咋的了解清楚,但是最后还是请教各种大神把问题给解决了。原因就是给了我几个授权文件,其后貌似就解决!这里我还是把工具给共享了吧!之前那个貌似已经过期了。http://download.csdn.net/detail/aibieqing241/7143229

VC:CString用法整理(转载) _vc cstring_aimar266的博客-程序员秘密

1.CString::IsEmpty BOOL IsEmpty( ) const; 返回值:如果CString 对象的长度为0,则返回非零值;否则返回0。 说明:此成员函数用来测试一个CString 对象是否是空的。 示例: 下面的例子说明了如何使用CString::IsEmpty。 // CString::IsEmpty 示例 CString s; ASSERT(

多分类Softmax和交叉熵的求导_多分类交叉熵求导_jamyuan11的博客-程序员秘密

多分类模型的输出层一般通过一个Softmax,之后使用交叉熵作为损失函数进行反向传播。本文主要对多分类模型中输出层的结果求偏导,为后续计算模型反向传播打下基础。

复杂度分析(二)_菜鸡本鸡的博客-程序员秘密

文章目录复杂度分析(二)01、最好、最坏情况时间复杂度02、平均情况时间复杂度03、均摊时间复杂度复杂度分析(二)01、最好、最坏情况时间复杂度// n 表示数组 array 的长度int find(int[] array, int n, int x) { int i = 0; int pos = -1; for (; i &lt; n; ++i) { if (array[i] == x) pos = i; } return pos;}这段代码的时间复杂度就是O(n

最新《游人客栈 安卓逆向基础教程 价值&》_aiwozhiai的博客-程序员秘密

课程目录第1课:环境搭建与工具使用介绍第2课:Dalvik指令与APK文件结构第3课:如何去除广告第4课:逆向之路的前奏第5课:逆向之路一!第6课:逆向之路二第7课:逆向之路三第8课:逆向之路四第9课:逆向之路五第10课:逆向之路六第11课:逆向之路七第12课:逆向之路八第13课:逆向之路九第14课:逆向之路完结 下载地址:百度网盘...

推荐文章

热门文章

相关标签