我有我的按钮,是从故事板创建的:
@property (weak, nonatomic) IBOutlet UIButton *plusOneBtnPoisonTwo;
用它的方法:
- (IBAction)plusOnePlayerTwoPoison:(id)sender;
然后我检查设备旋转并设置新位置:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
// NSLog(@"%d", toInterfaceOrientation);
if(!UIInterfaceOrientationIsPortrait(toInterfaceOrientation)){
self.plusOneBtnPoisonTwo.center = CGPointMake(284, 406);
}
}
按钮在新位置移动,但方法plusOnePlayerTwoPoison
不再触发......
任何的想法?
感谢。
答案 0 :(得分:0)
请尝试使用此功能。它只是猜测它可以解决你的问题。
@property (retain, nonatomic) IBOutlet UIButton *plusOneBtnPoisonTwo; //change to retain
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
//add button action manually by code
[plusOneBtnPoisonTwo addTarget:self action:@selector(plusOnePlayerTwoPoison:) forControlEvents:UIControlEventTouchDown];
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
// NSLog(@"%d", toInterfaceOrientation);
if(!UIInterfaceOrientationIsPortrait(toInterfaceOrientation)){
[plusOneBtnPoisonTwo setFrame:CGRectMake(284, 406,50,100)];
}
}