zoukankan      html  css  js  c++  java
  • 调整UIPickerView高度

    Advantages:

    1. Makes setFrame of UIPickerView behave like it should
    2. No transform code within your UIViewController
    3. Works within viewWillLayoutSubviews to rescale/position the UIPickerView
    4. Works on the iPad without UIPopover
    5. The superclass always receives a valid height
    6. Works with iOS 5

    Disadvantages:

    1. Requires you to subclass UIPickerView
    2. Requires the use of pickerView viewForRow to undo the transformation for the subViews
    3. 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;
    }
    

      

  • 相关阅读:
    50.2 Django 连接MySQL,django orm 数据库(models)操作
    50.1 Django 静态资源配置 static && form表单和 request对象
    JS备忘
    Python 单元测试 生产HTML测试报告
    python 单元测试 执行测试
    pycharm 安装插件
    Python 单元测试 实战演练
    Python 单元测试
    Pycharm 使用备忘
    Python 异常
  • 原文地址:https://www.cnblogs.com/cocoajin/p/3146795.html
Copyright © 2011-2022 走看看