화면에서 물체 (보기)가 튀는 UI 동적을 구현했습니다. 시뮬레이터에서 완벽하게 작동하지만 실제 아이폰에서 테스트 할 때 경계가 작동하지 않습니다. 필요하다면 나는 코드를 게시 할 것이다. 그러나 이것은 나에게 개념적으로 뭔가 빠져있는 것 같다. 어떤 팁이나 아이디어?UIDynamics 충돌이 실제 아이폰에서 작동하지 않습니다.
추가 세부 정보 : 경계가 화면을 둘러싸고 있으며 시뮬레이터의 두 가지 크기에서 테스트 한 결과 정상적으로 작동합니다.
는 "나쁜" "나쁜"중 하나 칠 때 무슨 일 (인스턴스 변수로 정의 된 또한 "screenWidth"와 "screenHeight")를 view--의 이름
///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