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;
    }
    

      

  • 相关阅读:
    Bootstrapbutton组
    Hadoop
    图像手工画效果【QT+OpenCV】
    经常使用传感器协议1:CJ/T-188 水表协议解析1
    神经网络的初识
    用队列实现栈
    sas数据导入终极汇总-之中的一个
    SPOJ 题目705 New Distinct Substrings(后缀数组,求不同的子串个数)
    怎样选择正确的HTTP状态码
    最新最全的iOS手机支付总结
  • 原文地址:https://www.cnblogs.com/cocoajin/p/3146795.html
Copyright © 2011-2022 走看看