【发布时间】:2015-11-20 13:22:51
【问题描述】:
我的视图上有几个按钮,当应用启动时,它们应该围绕 x 轴翻转。当我从 Xcode 启动应用程序(构建然后运行当前方案)时,它们会翻转,但是当我在 iPhone 上打开应用程序时,它们不会翻转。
我的 ViewController 中的 viewDidLoad 如下所示:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
model =[[Model alloc] init];
GameView *gameView = [[GameView alloc] initWithTiles];
gameView.controller = self;
self.view = gameView;
[self flipButtons];
}
当我从手机启动应用程序时,为什么按钮不翻转?
如果您需要更多信息,请告诉我 :)
编辑
这是翻转按钮并为每个按钮调用的方法:
- (void)flip:(Color*)color {
int flipDirection = arc4random() % 2;
if(flipDirection == 0) flipDirection = -1;
double duration = 200 + arc4random() % (500 - 200);
duration = duration / 1000;
// Animation
[UIView animateWithDuration:duration
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction
animations:^{
self.layer.transform = CATransform3DMakeRotation(M_PI, 0, flipDirection, 0);
// wait duration /2 and call changeColor
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)((duration / 2) * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self changeColor:color];
});
}
completion:^(BOOL finished) {
self.layer.transform = CATransform3DMakeRotation(M_PI, 0, 0, 0);
}];
}
【问题讨论】:
-
你说你的按钮在模拟器中翻转,而不是在设备中?
-
@Kathiravan 不,他们在我的设备上翻转,但前提是我从 Xcode 启动应用程序。
-
在您的翻转按钮方法中添加 NSlog。在设备中启动您的应用程序并在 Xcode 中检查设备控制台,检查您的方法是否被调用。
-
dispatch_after应该在完成块中。 -
@TamásZahola 请问为什么?
标签: ios objective-c iphone xcode