Peek and Pop新功能展示

//实现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 'com.github.shalskar:PeekAndPop:v0.1.1' }基本的使用很简单,只需一个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)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值