我在尝试在视图中弹出图像时遇到问题。我用图像创建了一个新的 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.mi 中有一个按钮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
视图控制器.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 *'
提前致谢。