简体   繁体   中英

How to change a anchor point of uibutton in [UIVIEW animate]?

I'm trying to change a anchor point to (0,0) (it's not center.) of uibutton and rotate.

How to change a anchor point of uibutton?

mybutton.anchorPoint? = CGPointMake(0, 0); <= How to change?
[UIView animateWithDuration:5.0 animations:^{
    mybutton.transform = CGAffineTransformMakeRotation(180 * M_PI / 180);
}];

Each CALayer has an anchorPoint property. You can do one of the following:

  • You can either animate the layer (the anchor is by default the center of the bounds)
  • You can combine a translation with a rotation transform (translate button center to origin, rotate and translate back)

EDIT:

Example: [button.layer setAffineTransform:CGAffineTransformMakeRotation(180 * M_PI / 180)]

I think you would set it by the following

    [button.layer setAnchorPoint:CGPointMake(button.frame.origin.x, button.frame.origin.y)];

But I'm only just playing with it myself. So not positive if it will work yet.

A

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM