Iphone UIImageView子类不显示

Iphone UIImageView子类不显示,iphone,uiimageview,subclassing,Iphone,Uiimageview,Subclassing,我正在使用UIImageView的一个自定义子类,但我不明白为什么它没有显示出来 The relevant code from my UIImageView subclass: -(id) initWithImage:(UIImage*)image{ if(self = [super initWithImage:image]){ } return self; } 以及将显示我的子类的视图的视图控制器: UIImage *zoomRatateSliderHorizont

我正在使用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];
使用断点,我检查了传递给我的类的帧和图像,它们看起来都是有效的和需要的

任何关于我做错了什么的建议,我都将不胜感激。

苹果文档如下:

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

因此,我将UIView子类化并从那里开始工作。

苹果文档如下:

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


因此,我将UIView子类化并从那里开始工作。

我对任何自定义绘图代码都不感兴趣。我的子类中的drawRect:是空的。如果你没有做自定义绘图,那么你的子类中根本不应该有
-drawRect:
(除非你调用super)。啊哈!谢谢你,瑞南。你的回答大大澄清了Mjoy。任何新手都要注意:当进行子类化时,一定要小心重写哪些方法。我对任何自定义绘图代码都不感兴趣。我的子类中的drawRect:是空的。如果你没有做自定义绘图,那么你的子类中根本不应该有
-drawRect:
(除非你调用super)。啊哈!谢谢你,瑞南。你的回答大大澄清了Mjoy。任何新手都要注意:当进行子类化时,一定要小心重写哪些方法。