Search code examples
iosipadcgrectmake

arc4random method reduces the size of button


below is a method i've written to respond to a shake so that the buttons are positioned randomly.

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {

    if (motion == UIEventSubtypeMotionShake)

    {
        for(int i=0;i<8;i++){
          CGAffineTransform angle = CGAffineTransformMakeRotation(arc4random());
          shieldButton[i].transform = angle;

          shieldButton[i].frame = CGRectMake(arc4random()%900, arc4random()%400, 140, 171);
        }
    }

}

but when I use the arc4random method, the size of the button gets reduced. what could be the reason ...?

Thanks.


Solution

  • This is from Apple's documentation

    Warning: If the transform property is not the identity transform, the value of this property is undefined and therefore should be ignored.

    Try setting bounds.