2012-04-22 6 views
-1

自分のビューで画像をポップアップしようとしたときに問題が発生しています。 私はUIView(UIViewImageOverlay.m)の新しいサブクラスをイメージと共に作成しました。私ViewController.miで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 

は、ビューをロードするためのボタン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

はあなたがUIViewImageOverlay のヘッダを投稿することができ、あなたのコントローラの実装ファイルでUIViewImageOverlay.hを含めますか? – giorashc

+0

@giorashc、私は自分の投稿を更新しました。 – JavaCake

+0

ここで、 'viewImageOverlay'プロパティの定義はどこですか? –

答えて

1

は、インスタンス変数viewImageOverlayを宣言し、プロパティ

+0

ViewController.hソースで私の更新されたコードを見てください。ありがとう – JavaCake

+0

なぜUIImageViewを使用する代わりにUIViewをカスタム描画するのか? – Zippo

+0

私はまったくそれを考慮しませんでした。私はカスタムドローと同じ能力を持っていますか? – JavaCake

1

あなたのコントローラのヘッダファイル(@class UIViewImageOverlay)で前方クラス宣言を持っているとして、それを定義します。これは正しい実装を陰にします。

+0

'ViewController.m'の上に' #import "UIViewImageOverlay.h"を追加しました。警告は解決されましたが、画像が表示されません。おそらくもう一つ別の問題です。 – JavaCake

+0

デバッグ時にdrawRectがロードされることはありません。 – JavaCake

関連する問題