调整UIPickerView高度
Advantages:
- Makes setFrame of
UIPickerView
behave like it should - No transform code within your
UIViewController
- Works within
viewWillLayoutSubviews
to rescale/position theUIPickerView
- Works on the iPad without
UIPopover
- The superclass always receives a valid height
- Works with iOS 5
Disadvantages:
- Requires you to subclass
UIPickerView
- Requires the use of
pickerView viewForRow
to undo the transformation for the subViews - UIAnimations might not work
Solution:
Subclass UIPickerView and overwrite the two methods using the following code. It combines subclassing, fixed height and the transformation approach.
#define FIXED_PICKER_HEIGHT 216.0f
- (void) setFrame:(CGRect)frame
{
CGFloat targetHeight = frame.size.height;
CGFloat scaleFactor = targetHeight / FIXED_PICKER_HEIGHT;
frame.size.height = FIXED_PICKER_HEIGHT;//fake normal conditions for super
self.transform = CGAffineTransformIdentity;//fake normal conditions for super
[super setFrame:frame];
frame.size.height = targetHeight;
CGFloat dX=self.bounds.size.width/2, dY=self.bounds.size.height/2;
self.transform = CGAffineTransformTranslate(CGAffineTransformScale(CGAffineTransformMakeTranslation(-dX, -dY), 1, scaleFactor), dX, dY);
} - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
//Your code goes here CGFloat inverseScaleFactor = FIXED_PICKER_HEIGHT/self.frame.size.height;
CGAffineTransform scale = CGAffineTransformMakeScale(1, inverseScaleFactor);
view.transform = scale;
return view;
}
调整UIPickerView高度的更多相关文章
- 动态调整UITableViewCell高度的实现方法
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPa ...
- vim: vs sp 调整窗口高度和宽度
转自:http://www.cnblogs.com/xuechao/archive/2011/03/29/1999292.html vim多窗口有时候需要调整默认的窗口宽度和高度,可以用如下命令配合使 ...
- Android - 动态调整ListView高度
布局中,如果设计ListView的高度为包裹内容,那么ListView的高度是随着它的子条目的数量的变化而改变的, 这就可能会导致ListView下面的一些控件的位置也会随着ListView的高度的变 ...
- 通过扩展jQuery UI Widget Factory实现手动调整Accordion高度
□ 实现Accordion高度一致 <head> <meta name="viewport" content="width=device-width&q ...
- 调整iFrame高度
在Chrome中,即使将iframe的高度设置为100%,也无法根据内容页自动调节高度,需要在iframe的onload even中通过计算设置iframe的高度 function setIframe ...
- ECharts树图节点过多时取消缩放,调整容器高度自适应内容变化
问题现象 使用ECharts树图,在数据维度大,节点过多时,所看到的内容会重叠交错,无法查看. 原因 在给定ECharts树图容器尺寸后,无论数据多么庞大或者稀少,数据始终会尝试在给定容器内撑满.全部 ...
- listctrl调整表头高度
CListCtrl派生类下CMyListCtrl.h class CMyListCtrl :public CListCtrl { public: // 设置表头高度 void SetHeadHeigh ...
- gnome3 调整标题栏高度
适用于:gtk 3.20 + 1. 在用户主目录 -/.config/gtk3.0/ 下新建gtk.css文件: 2. 复制如下css值: headerbar.default-decoration { ...
- 8.14 右键自定义菜单 更加iframe 内容高度调整 iframe高度 js定时
<div class="main_contain" id="z_div" style="position: relative;"> ...
随机推荐
- HDU step by step
section 1 不解释~ section 2 1.2.1 a+b coming #include<stdio.h> long long z,x,y; int main( ) { whi ...
- vue2.0使用记录
父组件给子组件传值[props] 1.首先在父组件的script标签中引入子组件 import Children from './Children' 2.在template内引入子组件 <Chi ...
- LAMP LNMP 和 LNMPA
LAMP指的是:Linux+Apache+MySQL+Perl/PHP/Python LAMP是一个缩写,它指一组通常一起使用来运行动态网站或者服务器的自由软件: Linux,操作系统: Apache ...
- How to edit the init.rc in android
We have to perform the following steps to edit your init.rc successfully: . Download the BOOT (R ...
- 修改WampServer的默认端口
WampServer默认的安装端口是80,容易和已安装的ISS等其他服务冲突,导致WampServer无法启动. 无法启动的现象如下: 1.apache服务无法启动.问题所在:80端口冲突. 2.在浏 ...
- Python机器学习实战<一>:环境的配置
详细要学习的书籍就是<机器学习实战>Machine Learning in Action,Peter Harrington Windows下要安装3个文件,各自是; 1.Python(因为 ...
- 为DropDownListFor设置选中项
在MVC中,当涉及到强类型编辑页,如果有select元素,需要根据当前Model的某个属性值,让Select的某项选中.本篇只整理思路,不涉及完整代码. □ 思路 往前台视图传的类型是List< ...
- 使用 MVC 5 的 EF6 Code First 入门 系列:建立一个EF数据模型
这是微软官方SignalR 2.0教程Getting Started with Entity Framework 6 Code First using MVC 5 系列的翻译,这里是第一篇:建立一个E ...
- JAVA nio 2 定义 Path 类
一旦确认了文件系统上的一个文件或目录,那么就可以定义一个 Path 类来指向它.定义 Path 类可以使用绝对路径.相对路径.路径中带有一个点号“.”(表示当前目录).路径中带有两个点“..”(表示上 ...
- 转: Go -- 单例
最近在学习Golang,想着可以就以前的知识做一些串通,加上了解到go语言也是面向对象编程语言之后.在最近的开发过程中,我碰到一个问题,要用go语言实现单例模式.本着“天下知识,同根同源”(我瞎掰的~ ...