我實現了在屏幕上彈跳的對象(視圖)的UIdynamics。在模擬器上,它可以完美地工作,但是當在真正的iPhone上測試時,邊界不起作用。如果有必要,我會發布代碼,但在我看來,就像我在概念上缺少某些東西。任何提示或想法?UIDynamics碰撞無法在物理iphone上運行
附加細節:屏幕周圍的邊界,我已經測試了兩種尺寸的模擬器,它工作正常。
「壞」是view--的名稱(也稱爲「屏幕寬度」和「screenHeight」已被定義爲實例變量)
///left wall
badCollision = [[UICollisionBehavior alloc] initWithItems:@[bad]];
badCollision.collisionDelegate = self;
CGPoint pt1 = CGPointMake(0, 0);
CGPoint pt2 = CGPointMake(0, screenHeight);
[badCollision addBoundaryWithIdentifier:@"leftWall" fromPoint:pt1 toPoint:pt2];
[animator addBehavior:badCollision];
//right wall
badCollision = [[UICollisionBehavior alloc] initWithItems:@[bad]];
badCollision.collisionDelegate = self;
pt1 = CGPointMake(screenWidth, 0);
pt2 = CGPointMake(screenWidth, screenHeight);
[badCollision addBoundaryWithIdentifier:@"rightWall" fromPoint:pt1 toPoint:pt2];
[animator addBehavior:badCollision];
//top wall
badCollision = [[UICollisionBehavior alloc] initWithItems:@[bad]];
badCollision.collisionDelegate = self;
pt1 = CGPointMake(0, 0);
pt2 = CGPointMake(screenWidth, 0);
[badCollision addBoundaryWithIdentifier:@"topWall" fromPoint:pt1 toPoint:pt2];
[animator addBehavior:badCollision];
//bottom wall
badCollision = [[UICollisionBehavior alloc] initWithItems:@[bad]];
badCollision.collisionDelegate = self;
pt1 = CGPointMake(0, screenHeight);
pt2 = CGPointMake(screenWidth, screenHeight);
[badCollision addBoundaryWithIdentifier:@"bottomWall" fromPoint:pt1 toPoint:pt2];
[animator addBehavior:badCollision];
這裏是當「壞」的歌曲之一,會發生什麼牆壁。
NSLog(@"Wall Hit");
UIPushBehavior *badForce = [[UIPushBehavior alloc] initWithItems:@[item] mode:UIPushBehaviorModeInstantaneous];
UIView *itemView = (UIView*)item;
itemView.backgroundColor = [UIColor redColor];
[UIView animateWithDuration:0.3 animations:^{
itemView.backgroundColor = [UIColor blueColor];
}];
int xneg = (int)drand48();
if (xneg < .51)
xneg = 1;
else
xneg = -1;
int yneg = (int)drand48();
if (yneg < .51)
yneg = 1;
else
yneg = -1;
double xSpeed = xneg*(drand48()+1)/20+.02;
double ySpeed = yneg*(drand48()+1)/20+.02;
badForce.pushDirection = CGVectorMake(xSpeed,ySpeed);
badForce.active = YES;
甚至沒有打印賬單會顯示在日誌中
你的權利,回想起來,這似乎很模糊。有多個視圖可以繪製20x20的矩形。這些以隨機方向施加的瞬時力開始。這些視圖沒有阻力,重力或摩擦。我更新了上面的代碼以顯示爲視圖創建的邊界。我還補充說碰撞事件會發生什麼。 – MingMan