Rotate UIBarButtonItem

后端 未结 4 416
时光说笑
时光说笑 2021-01-14 16:10

I want to rotate a UIBarButtonItem.

I have been able to do this with UIButtons using setTransform:CGAffineTransformMakeRotation(…)

4条回答
  •  再見小時候
    2021-01-14 16:37

    I extended UIToolBar, giving access to its subviews, and in it have a function rotate that rotates the buttons in the opposite direction of the bar:

    - (void)rotate: (int)degrees{
        //for the bar
        self.transform=CGAffineTransformMakeRotation(DegreesToRadian(degrees));
        //for the subviews (UIBarButtonItems)
        for (UIView * subView in self.subviews)
        {
            if(!CGRectEqualToRect(subView.bounds, self.bounds))
                subView.transform =   CGAffineTransformMakeRotation(DegreesToRadian(-degrees));
        }
    
    } 
    

提交回复
热议问题