У меня есть GameOver UIView, который я вызываю изнутри моего основного UIViewController. Это просто окно «popover», в котором есть текстовая игра, оценка и некоторые эффекты размытия, чтобы размыть основной 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];
}
У вас возникли проблемы с цветом фона представления? –