子类化UIVisualEffectView的问题

时间:2014-08-01 02:22:58

标签: ios objective-c parse-platform

我正在自定义Parse登录视图,我用库创建了模糊的背景,但现在我可以使用UIVisualEffectView。因为我有一个类作为PFLoginViewController的委托,所以我决定继承UIVisualEffectView并将其作为我的委托。问题是并非我的所有登录视图都显示出来。我知道我的框架设置正确。这是我的代码,可以更好地了解我所谈论的内容。

-(id)initWithEffect:(UIVisualEffect *)effect {

    self = [super initWithEffect:effect];

    [self setUpUserViews];

    return self;

}

- (void)setUpUserViews {

    NSLog(@"Setting Up View");

    CGRect size = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);

    //Initialize login and sign up views
    _loginView = [[PFLogInViewController alloc] init];
    _signUpView = [[PFSignUpViewController alloc] init];

    //Set their delegates to this view controller
    [_loginView setDelegate:self];
    [_signUpView setDelegate:self];

    //Set fields for sign up view
    [_signUpView setFields:PFSignUpFieldsEmail | PFSignUpFieldsUsernameAndPassword | PFSignUpFieldsSignUpButton];

    //Set sign up view for login view
    [_loginView setSignUpController:_signUpView];

    //Set up login view
    _loginView.view.frame = size;

    _loginView.view.backgroundColor = [UIColor clearColor];

    [_loginView.logInView setLogo:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"banner.png"]]];

    //Set Login Button
    [_loginView.logInView.logInButton setBackgroundImage:[UIImage imageNamed:@"orange.png"] forState:UIControlStateNormal];
    [_loginView.logInView.logInButton setBackgroundImage:[UIImage imageNamed:@"orangeDown.png"] forState:UIControlStateHighlighted];

    //Set login text color
    [_loginView.logInView.logInButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    [_loginView.logInView.logInButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];

    //Set sign up button
    [_loginView.logInView.signUpButton setBackgroundImage:[UIImage imageNamed:@"green.png"] forState:UIControlStateNormal];
    [_loginView.logInView.signUpButton setBackgroundImage:[UIImage imageNamed:@"greenDown.png"] forState:UIControlStateHighlighted];

    //Set sign up button text color
    [_loginView.logInView.signUpButton setTitleColor:[UIColor colorWithRed:0.0 green:1.0 blue:0.0 alpha:0.6] forState:UIControlStateNormal];
    [_loginView.logInView.signUpButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];

    //Set dismiss button
    [_loginView.logInView.dismissButton setImage:nil forState:UIControlStateNormal];
    [_loginView.logInView.dismissButton setImage:nil forState:UIControlStateHighlighted];

    [_loginView.logInView.dismissButton setBackgroundImage:nil forState:UIControlStateHighlighted];
    [_loginView.logInView.dismissButton setBackgroundImage:nil forState:UIControlStateNormal];

    [_loginView.logInView.dismissButton setBackgroundImage:[UIImage imageNamed:@"dismiss.png"] forState:UIControlStateHighlighted];
    [_loginView.logInView.dismissButton setBackgroundImage:[UIImage imageNamed:@"dismiss.png"] forState:UIControlStateNormal];

    //Set forgotten button
    [_loginView.logInView.passwordForgottenButton setImage:[UIImage imageNamed:@"forgot.png"] forState:UIControlStateNormal];
    [_loginView.logInView.passwordForgottenButton setImage:[UIImage imageNamed:@"forgot.png"] forState:UIControlStateHighlighted];

    [_loginView.logInView.passwordForgottenButton setBackgroundImage:nil forState:UIControlStateNormal];
    [_loginView.logInView.passwordForgottenButton setBackgroundImage:nil forState:UIControlStateHighlighted];

    //Use custom method for showing sign up view
    [_loginView.logInView.signUpButton  removeTarget:nil action:NULL  forControlEvents:UIControlEventAllEvents];

    [_loginView.logInView.signUpButton  addTarget:self action:@selector(customViewMethod) forControlEvents:UIControlEventTouchUpInside];

    //Set up sign up view
    _signUpView.signUpView.backgroundColor = [UIColor clearColor];

    //Set sign up button
    [_signUpView.signUpView.signUpButton setImage:[UIImage imageNamed:@"green.png"] forState:UIControlStateNormal];
    [_signUpView.signUpView.signUpButton setImage:[UIImage imageNamed:@"greenPress.png"] forState:UIControlStateHighlighted];

    [_signUpView.signUpView.signUpButton setBackgroundImage:nil forState:UIControlStateNormal | UIControlStateHighlighted];

    //Present login view
    [self.contentView addSubview:_loginView.view];
}

这是我所获得的截图。左上角有一个X.这是登录视图的一部分:

enter image description here

以下是它应该是什么样子的截图:

enter image description here

1 个答案:

答案 0 :(得分:0)

问题已经解决了。问题是事情很快就会从内存中释放出来,导致有nil代表。