Ios 按钮下方的弹出图像

Ios 按钮下方的弹出图像,ios,uiview,uiviewcontroller,Ios,Uiview,Uiviewcontroller,我尝试在视图中弹出图像时遇到问题。 我已经用这个图像创建了UIView的一个新子类(UIViewImageOverlay.m) UIViewImageOverlay.m // ImageOverlay.m // ButtonPopup // // #import "UIViewImageOverlay.h" @implementation UIViewImageOverlay - (id)initWithFrame:(CGRect)frame { self = [super i

我尝试在视图中弹出图像时遇到问题。 我已经用这个图像创建了UIView的一个新子类(UIViewImageOverlay.m)

UIViewImageOverlay.m

//  ImageOverlay.m
//  ButtonPopup
//
//

#import "UIViewImageOverlay.h"

@implementation UIViewImageOverlay

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}


// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    CGContextRef contextRef = UIGraphicsGetCurrentContext();
    UIImage *myImage = [UIImage imageNamed:@"test.jpeg"];
    int w = myImage.size.width;
    int h = myImage.size.height;
    CGContextDrawImage(contextRef, CGRectMake(0, 0, w, h), myImage.CGImage);
    CGContextRelease(contextRef);
}


@end
在我的ViewController.m中,我有一个按钮
pushPush
,用于加载视图,但尝试会发出警告

//  ViewController.m
//  ButtonPopup
//
//

#import "ViewController.h"
#import "UIViewImageOverlay.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize viewImageOverlay;



- (void)viewDidLoad
{
    [super viewDidLoad]; // static
}

- (void)viewDidUnload
{

    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    } else {
        return YES;
    }
}

- (IBAction)pushPush:(id)sender {
    [self.view addSubview:self.viewImageOverlay];
}
@end
ViewController.h

//  ViewController.h
//  ButtonPopup
//

#import <UIKit/UIKit.h>
@class UIViewImageOverlay;


@interface ViewController : UIViewController {
    UIViewImageOverlay *viewImageOverlay;
}

@property(nonatomic, retain) UIViewImageOverlay *viewImageOverlay; 
- (IBAction)pushPush:(id)sender;
@end
//ViewController.h
//纽扣小狗
//
#进口
@类UIViewImageOverlay;
@界面ViewController:UIViewController{
UIViewImageOverlay*viewImageOverlay;
}
@属性(非原子,保留)UIViewImageOverlay*viewImageOverlay;
-(iAction)推送:(id)发送方;
@结束
UIViewImageOverlay.h

//  ImageOverlay.h
//  ButtonPopup
//
//

#import <UIKit/UIKit.h>

@interface UIViewImageOverlay : UIView

@end
//ImageOverlay.h
//纽扣小狗
//
//
#进口
@界面UIViewImageOverlay:UIView
@结束
[self.view addSubview:self.viewImageOverlay]报告
不兼容的指针类型将“UIViewImageOverlay*”发送到“UIView*”类型的参数。


提前感谢。

声明实例变量viewImageOverlay并将其定义为属性

在控制器的头文件(
@class UIViewImageOverlay
)中有一个前向类声明。它隐藏了正确的实现


uiviewmageoverlay.h
包含在控制器的实现文件中

您可以发布uiviewmageoverlay的标题吗?@giorashc,我已经更新了我的帖子。属性
viewmageoverlay
的定义在哪里?从我在这里看到的情况来看,它应该可以工作@t_motooka的问题可能会揭开这个谜团:)呜呜!我的坏,现在包括viewcontroller.h!请参阅我更新的ViewController.h源代码。感谢你自定义UIVIEW而不是使用UIVIEVIEW的原因吗?我根本没有考虑过。我是否具有与自定义绘图相同的能力?取决于你想做什么。请参阅文档以查看该类是否符合您的需要。您自己看到的定位非常简单。您的自定义绘图方法很可能没有被调用,因为您没有在相应的头文件中声明它。我在
ViewController.m
的顶部添加了
#import“uiviewmageoverlay.h”
。警告现在已解决,但没有图像弹出。现在很可能是另一个问题。