Peek and Pop新功能展示

本文介绍如何在iOS应用中使用InfoListTableViewController并实现与3D Touch的交互,包括设置代理方法、数据源方法以及预览和弹出视图的处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//实现UIViewControllerPreviewingDelegate代理方法

@interface InfoListTableViewController : UITableViewController <UIViewControllerPreviewingDelegate>


@end


//

//  InfoListTableViewController.m

//  Test3DTouch

//

//  Created by ios01 on 15/12/16.

//  Copyright © 2015 ios01. All rights reserved.

//


#import "InfoListTableViewController.h"

#import "InfoDetailViewController.h"


@interface InfoListTableViewController ()


@property (nonatomic, retain) NSMutableArray *arrDatas;

@property (strong, nonatomic) IBOutlet UITableView *showTableView;


@end


@implementation InfoListTableViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    

    [self setArrDatas:[NSMutableArray arrayWithArray:@[@"1111", @"2222"]]];

    [_showTableView reloadData];

    

    // 注册pep代理方法

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

    

    // Uncomment the following line to preserve selection between presentations.

    // self.clearsSelectionOnViewWillAppear = NO;

    

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.

    // self.navigationItem.rightBarButtonItem = self.editButtonItem;

}


- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


#pragma mark - Table view data source


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

//#warning Incomplete implementation, return the number of sections

    return 1;

}


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

//#warning Incomplete implementation, return the number of rows

    NSLog(@"");

    return [_arrDatas count];

}



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

    static NSString *cellIdentifier = @"cellIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    

    // Configure the cell...

    if (cell==nil) {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];

    }

    [cell.textLabel setText:[_arrDatas objectAtIndex:indexPath.row]];

    

    return cell;

}



#pragma mark - peek和pop代理方法

//预览界面代理方法

- (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)context viewControllerForLocation:(CGPoint) point

{

    InfoDetailViewController *childVC = [[InfoDetailViewController alloc] initWithNibName:@"InfoDetailViewController" bundle:nil];

    NSIndexPath* indexpath = [_showTableView indexPathForRowAtPoint:point];

    if (indexpath.row==0) {

        [childVC setStrUrl:@"https://www.baidu.com"];

    }

    else {

        [childVC setStrUrl:@"http://www.sina.com"];

    }

//    UIViewController *childVC = [[UIViewController alloc] init];

    childVC.preferredContentSize = CGSizeMake(0.0f,300.0f);

    

    CGRect rect = CGRectMake(10, point.y - 10, self.view.frame.size.width - 20,20);

    context.sourceRect = rect;

    return childVC;

}


//继续按压后,跳转到需要展示的界面

- (void)previewingContext:(id<UIViewControllerPreviewing>)context commitViewController:(UIViewController*)vc

{

    [self showViewController:vc sender:self];

}



@end



一个模仿iOS中3D Touch效果的库,因为安卓本身不支持3D Touch,所以事件的触发是用长按点击来替代。项目地址:https://github.com/shalskar/PeekAndPop demo地址:https://github.com/shalskar/PeekAndPopDemo 效果图:使用说明:开始这个库托管在 Jitpack.io,所以在根 build.gradle文件中添加:allprojects {     repositories {        ...         maven { url "https://jitpack.io" }     } }然后在application的 build.gradle文件中添加如下依赖:dependencies {     compile &#39;com.github.shalskar:PeekAndPop:v0.1.1&#39; }基本的使用很简单,只需一个activity实例,一个为 peek and pop准备的布局文件,一个或者多个在长按之后显示的 peek and pop视图。PeekAndPop peekAndPop = new PeekAndPop.Builder(this)                 .peekLayout(R.layout.peek_view)                 .longClickViews(view)                 .build();你可以调用PeekAndPop对象的getPeekView()来得到 peek view ,并使用 findViewById() 来得到 peek layout中的任意视图。View peekView = peekAndPop.getPeekView(); ImageView imageView = peekView.findViewById(R.id.image_view); TextView textView = peekView.findViewById(R.id.text_view);通常你可能还会想在列表中的某个item被点击时显示peek and pop ,为了让peek and pop正常工作,你需要添加这行代码:                .parentViewGroupToDisallowTouchEvents(viewGroup)
The goal of task 1 The goal of this exercise is to implement a Stack data structure. The implementation must pass all the tests included in the exercise. Time complexity requirements: capacity(): O(1). push(): O(1), except for when reallocation must be done: O(n). pop(): O(1). peek(): O(1). size(): O(1). isEmpty(): O(1). toString(): O(n). clear(): O(1). When implementing clear() you may decide yourself if you want to keep the current capacity or will the capacity be the default capacity of a queue. Note that the method toString() in this and later execises must be implemented using Java StringBuilder, not by using the String by modifying and appending to a String object. When handling large amounts of data elements, with String, this is hundreds of times slower than using StringBuilder. This has already been implemented for you. Prerequisites You have all the tools installed and working. This was tested in the 00-init exercise of the course. If you haven&#39;t done that yet, do it now. Instructions An overview of the classes in this exercise is shown in the UML class diagram below. Note that in this task, you only work with the StackImplementation class. The class ParenthesisTChecker.java and StackFactory.createCharacterStack() are not needed until you start working with the additional tasks. If you want to, you may crete your own main app file, for example in src/main/java/oy/tol/tra/Main.java, where you may implement your own main() method to experiment with your stack implementation. However, the main goal of the exercise is to pass all the unit tests. Do not implement main() method to data structure classes or test classes! Before delivery, remove all main functions an any unnrcessary test code. UML class diagram You should implement the interface StackInterface in the StackImplementation.java which is already created for you and located in this project&#39;s src/main/java/oy/tol/tra/ directory! Note that the StackImplementation uses E template parameter for the StackInterface: public class StackImplementation<E> implements StackInterface<E> { So the stack is a generic (template) class. Make sure to read the StackInterface documentation (the comments in the code) carefully so that your implementation follows the interface documentation. Obviously you need to know how stacks work in general, so check out the course lectures and other material on stack data structures. In this exercise, you use the Java plain array as the internal data structure for holding the elements: private Object [] itemArray; Since all Java classes inherit from Object, we can create an array of Objects for the elements. In the StackImplemention, constructors, follow the code comments and allocate the array of elements, in addition to other things you need to implement: itemArray = new Object[capacity]; Make sure to implement reallocating more room in the StackImplementation internal array if array is already full, when push() is called! After you have implemented your stack class methods, you can see that it is already instantiated for you in StackFactory.createIntegerStack(). After this, you are ready to test your implementation.
03-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值