UIImageView子类不显示

时间:2009-07-27 02:03:04

标签: iphone uiimageview subclassing

我正在使用UIImageView的自定义子类,但我无法弄清楚它为什么没有显示。

The relevant code from my UIImageView subclass:
-(id) initWithImage:(UIImage*)image{
    if(self = [super initWithImage:image]){

    }
    return self;
}

从视图控制器中查看将显示我的子类:

UIImage *zoomRatateSliderHorizontal = 
       [[UIImage imageNamed:@"ZoomRotate Slider Horizontal.png"]
      stretchableImageWithLeftCapWidth:(75.0)/2-1.0  topCapHeight:0]; 
scaleHorizontalControl = [[ViewTransformationController alloc] 
                     initWithImage:zoomRatateSliderHorizontal];
scaleHorizontalControl.onScreenFrame = CGRectMake(0.0, 5.0,  
                                   self.view.frame.size.width, 
                                   scaleHorizontalControl.image.size.height);
scaleHorizontalControl.frame = scaleHorizontalControl.onScreenFrame;
scaleHorizontalControl.offScreenFrame = CGRectZero;
[self.view addSubview:scaleHorizontalControl];

在我进行子类化之前,我在视图控制器中遇到以下问题:

UIImage *zoomRatateSliderVertical = 
                    [[UIImage imageNamed:@"ZoomRotate Slider Vertical.png"]
                    stretchableImageWithLeftCapWidth:0  topCapHeight:(75.0)/2-1.0]; 
scaleOrRatateViewVertical = [[UIImageView alloc] 
                             initWithImage:zoomRatateSliderVertical];
scaleOrRatateViewVertical.frame = CGRectMake(-zoomRatateSliderVertical.size.width,
                                  zoomRatateSliderHorizontal.size.height+5.0+5.0, 
                                  zoomRatateSliderVertical.size.width, 
                           465.0 - zoomRatateSliderHorizontal.size.height-10.0-5.0);
[self.view addSubview:scaleOrRatateViewVertical];

使用断点我检查了帧和图像是否正在传递给我的班级,它们看起来都是有效的。

关于我做错的任何建议我都非常感激。

1 个答案:

答案 0 :(得分:4)

Apple Docs阅读:

  

优化UIImageView类以将其图像绘制到显示器。 UIImageView不会调用drawRect:一个子类。如果您的子类需要自定义绘图代码,建议您使用UIView作为基类。

所以我将UIView子类化并从那里开始工作。