First, never change the interface outside the main thread. Therefore, your code should change the code:
dispatch_async(drawingQue, ^{
Secondly, never change the interface inside the shouldAutorotateToInterfaceOrientation method. All you have to do inside this method is return whether the view should rotate or not. For example, in some cases when you have a view controller hierarchy, the view may not rotate, even if you return YES in shouldAutorotateToInterfaceOrientation .
So you have to call your code inside the method:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
This can be achieved in many ways. The easiest (and the one I recommend) is to use the standard Objective-C method:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) { // landscape [self rotateButtonWithA:234 b:24]; } else { // portrait [self rotateButtonWithA:123 b:24]; } } - (void)rotateButtonWithA:(CGFloat)ab:(CGFloat)b { dispatch_async(drawingQue, ^{ // ... dispatch_async(dispatch_get_main_queue(), ^{ button.frame= CGRectMake(x+y, xy, a, b); [button setTitle:@"abc"]; }); }); }
You really do not need to call the block itself from several places. But if you still want to do this, there are many answers here that show how to do this.
sch
source share