簡體   English   中英

使用CGRectMake移動子視圖會導致崩潰

[英]Moving a subview with CGRectMake causes crash

我試圖通過單擊按鈕來移動子視圖,但是它崩潰了,並給了我-[MainGameDisplay openTimeChanger:]: unrecognized selector sent to instance 0x10e443d0

這是我在做什么:

@interface:
UIImageView *changerBackground;
@implementation

timerView = [[UIView alloc] initWithFrame:CGRectMake(0, 278, 105, 27)];
[self.view addSubview:timerView];

changerBackground = [[UIImageView alloc] init];
[changerBackground setImage:[UIImage imageNamed:@"speedbackground.png"]];
changerBackground.frame = CGRectMake(-12 , 9, 105, 33);
[changerBackground setUserInteractionEnabled:YES];
[timerView addSubview:changerBackground];

UIButton *timerBackground = [UIButton buttonWithType:UIButtonTypeCustom];
[timerBackground setBackgroundImage:[UIImage imageNamed:@"Time Background.png"] forState:UIControlStateNormal];
[timerBackground setBackgroundImage:[UIImage imageNamed:@"Time Background.png"] forState:UIControlStateHighlighted];
[timerBackground addTarget:self action:@selector(openTimeChanger:) forControlEvents:UIControlEventTouchUpInside];
timerBackground.frame = CGRectMake(-2 , 15, 102, 27);
[timerView addSubview:timerBackground];



-(void)openTimeChanger {
    [UIView animateWithDuration:0.2f
                     animations:^{
                         changerBackground.frame = CGRectMake(-12 , -16, 105, 33);
                     }
                     completion:Nil];
}

還要注意changerBackground有3個子視圖。

你需要改變這個

[timerBackground addTarget:self action:@selector(openTimeChanger:) forControlEvents:UIControlEventTouchUpInside];

[timerBackground addTarget:self action:@selector(openTimeChanger) forControlEvents:UIControlEventTouchUpInside]; //note that semicolon is not there in the method name

您的方法定義是-(void)openTimeChanger而不是-(void)openTimeChanger:(id)sender 它試圖找到具有此定義的方法,但該方法不可用,因此導致崩潰。

如果要使用[timerBackground addTarget:self action:@selector(openTimeChanger:) forControlEvents:UIControlEventTouchUpInside]; ,然后將您的方法更改為-(void)openTimeChanger:(id)sender

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM