我在尝试在视图中弹出图像时遇到问题。 我用图像创建了一个新的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
UIViewImageOverlay.h
// ImageOverlay.h
// ButtonPopup
//
//
#import <UIKit/UIKit.h>
@interface UIViewImageOverlay : UIView
@end
[self.view addSubview:self.viewImageOverlay];
举报Incompatible pointer types sending 'UIViewImageOverlay *' to parameter of type 'UIView *'
提前致谢。
答案 0 :(得分:1)
声明实例变量viewImageOverlay并将其定义为属性
答案 1 :(得分:1)
您的控制器头文件(@class UIViewImageOverlay
)中有一个前向类声明。它会影响正确的实现。
在控制器的实施文件中包含UIViewImageOverlay.h