设备旋转后,UIButton不会运行操作

时间:2014-01-28 01:46:17

标签: ios xcode uibutton

我有我的按钮,是从故事板创建的:

@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不再触发...... 任何的想法? 感谢。

1 个答案:

答案 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)];

    }

}