UIPopoverController 是iPad的专属API

ViewController.m

#import "ViewController.h"
#import "DJMenuViewController.h" @interface ViewController () - (IBAction)leftItemDidClick:(id)sender; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; } - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} - (IBAction)leftItemDidClick:(id)sender { DJMenuViewController *menuVC = [[DJMenuViewController alloc] init];
UINavigationController *menuNavVC = [[UINavigationController alloc] initWithRootViewController:menuVC]; // 创建一个popoverController,注意!只能使用initWithContentViewController创建!
// 在iOS7以下的系统中,需要将popoverVC当做一个成员变量,使用一个强指针进行引用,否则在这段代码执行完毕后,popoverVC将被销毁
UIPopoverController *popoverVC = [[UIPopoverController alloc] initWithContentViewController:menuNavVC];
// 设置popoverController的内部尺寸
popoverVC.popoverContentSize = CGSizeMake(, *);
// 显示popoverController,有点类似于android里面的popview的showAsDropDown方法
[popoverVC presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; }
@end

DJMenuViewController.m

#import "DJMenuViewController.h"
#import "DJTestViewController.h" @interface DJMenuViewController() @property (nonatomic,strong) NSArray *titles; @end @implementation DJMenuViewController - (void)viewDidLoad { [super viewDidLoad];
self.titles = @[@"发起群聊",@"添加朋友",@"扫一扫",@"收付款"]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.titles.count;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *ID = @"title";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
} cell.textLabel.text = self.titles[indexPath.row];
return cell;
} - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { DJTestViewController *testVC = [[DJTestViewController alloc] init];
[self.navigationController pushViewController:testVC animated:YES]; } @end

DJTestViewController.m

#import "DJTestViewController.h"

@implementation DJTestViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    self.view.backgroundColor = [UIColor redColor];
} @end

Main.stroyboard

最终运行效果:

QQ空间HD(1)-UIPopoverController基本使用的更多相关文章

  1. QQ空间HD(2)-UIPopoverController其它使用

    DJTestViewController.m #import "DJTestViewController.h" #import "DJColorTableViewCont ...

  2. QQ空间HD(6)-实现自定义的选项卡切换效果

    DJTabbarButton.m #import "DJTabbarButton.h" @implementation DJTabbarButton - (instancetype ...

  3. QQ空间HD(5)-添加左侧菜单栏内容

    DJIconView.m #import "DJIconView.h" @implementation DJIconView - (instancetype)initWithFra ...

  4. QQ空间HD(4)-设置左侧菜单栏属性

    DJHomeViewController.m #import "DJHomeViewController.h" #import "DJMenuView.h" ; ...

  5. QQ空间HD(3)-Modal的切换效果总结

    - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { UIViewController ...

  6. iOS开发UI篇—模仿ipad版QQ空间登录界面

    iOS开发UI篇—模仿ipad版QQ空间登录界面 一.实现和步骤 1.一般ipad项目在命名的时候可以加一个HD,标明为高清版 2.设置项目的文件结构,分为home和login两个部分 3.登陆界面的 ...

  7. QQ空间动态爬虫

    作者:虚静 链接:https://zhuanlan.zhihu.com/p/24656161 来源:知乎 著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 先说明几件事: 题目的意 ...

  8. 仿QQ空间根据位置弹出PopupWindow显示更多操作效果

    我们打开QQ空间的时候有个箭头按钮点击之后弹出PopupWindow会根据位置的变化显示在箭头的上方还是下方,比普通的PopupWindow弹在屏幕中间显示好看的多. 先看QQ空间效果图:       ...

  9. QQ空间/朋友圈类界面的搭建

    类似于QQ空间的布局主要是在说说信息.点赞.回复三大部分的自适应布局上. 当我们需要搭建类似QQ空间.微信朋友圈的界面的时候,可做如下操作: 创建一个对应的model类: 创建一个对应model类的f ...

随机推荐

  1. Using the rJava package on Win7 64 bit with R

    加载 rJava 包报错: > library(rJava) Error : loadNamespace()里算'rJava'时.onLoad失败了,详细内容: 调用: fun(libname, ...

  2. python3 连接SQLserver

    pymssql 是Python语言用来连接微软 SQL SERVER 数据库的类库,实现了 Python DB API 2.0 .官网介绍. 最简事例: #!/usr/bin/env python # ...

  3. 【caffe】epoch,[batch_size],iteration的含义

    @tags caffe 概念 一个epoch表示"大层面上的一次迭代",也就是指,(假定是训练阶段)处理完所有训练图片,叫一个epoch 但是每次训练图片可能特别多,内存/显存塞不 ...

  4. 【poj2823】 Sliding Window

    http://poj.org/problem?id=2823 (题目链接) 题意 维护滑动窗口最大最小值. Solution sb单调队列 代码 // poj2823 #include<algo ...

  5. 【poj3237】 Tree

    http://poj.org/problem?id=3237 (题目链接) 树链剖分模板题,然而这150+行的程序我调了一天,历经艰辛,终于ac.. 题意 给出一个n个节点的带权树,要求维护操作:1. ...

  6. 【poj1014】 Dividing

    http://poj.org/problem?id=1014 (题目链接) 题意 给出有分别价值为1,2,3,4,5,6的6种物品,输入6个数字,表示相应价值的物品的数量,问一下能不能将物品分成两份, ...

  7. 关于git的学习

    Git是目前世界上最先进的分布式版本控制系统(没有之一)! 由于现在用的还不多,还没有这种体会,但是前人的经验是值得借鉴的,所以我认真的学习了一些关于git的简单操作,现在在这分享一些心得,或者说是为 ...

  8. GPU keylogger && GPU Based rootkit(Jellyfish rootkit)

    catalog . OpenCL . Linux DMA(Direct Memory Access) . GPU rootkit PoC by Team Jellyfish . GPU keylogg ...

  9. ruby 淘宝镜像

    由于国内GFW原因,导致无法安装gem库文件.故选择淘宝镜像, 如何使用? $ gem sources --remove https://rubygems.org/ $ gem sources -a ...

  10. href和src的使用场景

    href和src的使用场景 href和src的用法虽然简单,但是有时候会突然记不起来该怎么用,且两者不可相互替换,下面列出来方便记忆,并给出具体区别. href的使用: 1.外部css引用:<l ...