我有我從主UIViewController內調用的GameOver UIView。這只是一個'彈出窗口'窗口,它具有文本遊戲結束,分數和一些模糊效果,以模糊主UIViewcontroller。UIView不接受UIViewControllers數據
我嘗試將一個int傳遞給UIView,但它不接受它,除非它在- (void)drawRect:(CGRect)rect
方法中。
如果我將樂譜標籤移動到drawRect方法,標籤將被更新。但模糊效果消失。
我在做什麼錯?
MainViewController.m
#import "GameOverView.h"
@interface ViewController() {
GameOverView * gov;
}
- (void) showGameOver {
gov = [[GameOverView alloc] initWithFrame:self.view.bounds];
NSLog(@"Passing score of: %i", self.score);
gov.finalScore = self.score;
[self.view addSubview:gov];
}
GameOverView.h
@interface GameOverView : UIView {}
@property (nonatomic) int finalScore;
@end
GameOverView.M
@implementation GameOverView
- (id) initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code
//self.backgroundColor = [UIColor redColor];
NSLog(@"Score:%i", self.finalScore );
UIVisualEffect *blurEffect;
blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *visualEffectView;
visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
visualEffectView.frame = super.bounds;
[super addSubview:visualEffectView];
UILabel * lblGameOver = [[UILabel alloc] initWithFrame:CGRectMake(0,0, frame.size.width, 200)];
lblGameOver.center = CGPointMake(frame.size.width/2, 100);
lblGameOver.text = [NSString stringWithFormat: @"GAME OVER %i", self.finalScore];
[self addSubview:lblGameOver];
UIButton * button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, 200)];
button.center = CGPointMake(frame.size.width/2, 200);
[button setTitle:@"Start New Game" forState:UIControlStateNormal];
[button addTarget:self action:@selector(removeSelfFromSuperview) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:button];
}
return self;
}
- (void) removeSelfFromSuperview{
[self removeFromSuperview];
}
您是否對視圖背景顏色有任何問題? –