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. Java反编译插件JadClipse

    Java反编译是很容易的,现在就介绍一个反编译插件,以后我们通过Ctrl+鼠标左键查看源码就容易得多了,不用再担心源码找不到了,配置过程很简单的. 准备: 1.下载JadClipse(jar文件,ec ...

  2. 解决jQuery UI 对话框兼容性问题

    默认情况下使用jQuery UI的对话框,在Chrome浏览器是没问题的,但是在IE里却会显示对话框,用户体验非常不好.改变一下div的属性即可. 原本是这样: <div id="di ...

  3. [bzoj3670][2014湖北省队互测week2]似乎在梦中见过的样子

    Description 已知一个字符串S,求它有多少个形如A+B+A的子串(len(A)>=k,len(B)>=1 ). Input 第一行一个字符串,第二行一个数 k. Output 仅 ...

  4. Leetcode 198 House Robber

    You are a professional robber planning to rob houses along a street. Each house has a certain amount ...

  5. Android成长日记-WebView使用

    在App中有时候会看到一些页面是以网页的形式展示,其原理就是运用了WebView,下面予以讲述WebView 1. 使用Intent调用系统浏览器或者第三方浏览器打开网页 调用系统浏览器打开页面 Ur ...

  6. SQL查询——SQL LEFT JOIN/SQL RIGHT JOIN

    简介 在实际情况下,比如在一个大学里,有很多老师,老师都有自己的研究方向和职称.并且,可能并不是每个老师都带有研究生,如果一个新来的老师,可能还没有带研究生.所以,如果领导要求查出所有老师带研究生的数 ...

  7. 有关Java的日期处理的一些杂记

    在企业应用开发中,经常会遇到日期的相关处理,说实话JDK自带的日期方法很难用.就我个人而言我一般都会采用joda-time来替代JDK自身的日期. 这篇文章是杂记,所以写的比较零散,希望大家不要见怪. ...

  8. .net中ckeditor的应用

    ①js文件的引入 <script src="/public/ckeditor_4.4.7/ckeditor.js"></script> <script ...

  9. Linux以外的开源操作系统大汇总

    开源操作系统即公开源代码的操作系统软件,它遵循开源协议使用.编译和发布.自由和开放源代码软件中最著名的是Linux,它是一种类Unix的操作系统.Linux可安装在各种计算机硬件设备中,比如手机.平板 ...

  10. bootstrap学习总结-03 常用标签1

    1 显示段落 在HTML中,段落使用p标签包起来,重要的文字使用strong标签,em标签.<em> 标签告诉浏览器把其中的文本表示为强调的内容.对于所有浏览器来说,这意味着要把这段文字用 ...