Hey all! So basically I'm creating a custom UIButton, done so by creating a subclass of UIButton. Everything on the appearance side works great, except orientation changes. Normally, I pass two sets of CGRects to my custom button; one for portrait dimensions, and one for landscape. When the device changes orientation, I would like my button to change its frame to the portrait or landscape dimensions, depending on the orientation. My issue is getting my subclass to recognize orientation changes. Here's what I have tried:
In my custom button class's init method, among other button-related things, I have:
Then in my receivedRotate:
What's kind of interesting in all this is that on the simulator, it actually sometimes works. Most of the time, though, it gives me either of these in the output:
or
Both of these also give me the error "Thread 1: signal SIGABRT" at the line "return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));" in my main.m.
The fact that it sometimes works is new for me, though I think it may be related to the rendering that I have going on in the background. Maybe the other program taking up the CPU from my MacBook is somehow helping the simulator? I have no idea.
What's even weirder is that this only works around 1 in 6 times if I also have these methods included in my subclass:
When I take these methods out, it never works. When I put them back, it sometimes works. They really should be irrelevant, because as far as I know, they aren't being used anywhere else by my subclass.
Please, if anyone has any ideas, it is always appreciated. Even if you don't know the answer directly, but know some other source that may (which is unlikely, since I've scoured the net before this post), please point me in that direction, otherwise I may actually go insane working on this subclass.
Please, if anyone has any ideas, they are always appreciated. I may actually go insane if I never figure this out and really need to finish this subclass, so any help is greatly appreciated. Thank you.
In my custom button class's init method, among other button-related things, I have:
Code:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
Then in my receivedRotate:
Code:
- (void)receivedRotate:(NSNotification *)notification {
NSLog(@"yep, the orientation changed");
}
What's kind of interesting in all this is that on the simulator, it actually sometimes works. Most of the time, though, it gives me either of these in the output:
(lldb)
or
2012-06-06 02:47:32.220 Custom Keyboard Test[6639:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIControlTargetAction receivedRotate:]: unrecognized selector sent to instance 0xbe306f0'
Both of these also give me the error "Thread 1: signal SIGABRT" at the line "return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));" in my main.m.
The fact that it sometimes works is new for me, though I think it may be related to the rendering that I have going on in the background. Maybe the other program taking up the CPU from my MacBook is somehow helping the simulator? I have no idea.
What's even weirder is that this only works around 1 in 6 times if I also have these methods included in my subclass:
Code:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation) toInterfaceOrientation:(NSTimeInterval)duration {
NSLog(@"changed");
}
Code:
- (void)application:(UIApplication *)application willChangeStatusBarFrame:(CGRect)newStatusBarFrame {
NSLog(@"changed");
}
Code:
- (void)orientationChanged:(NSNotification *)notification {
}
When I take these methods out, it never works. When I put them back, it sometimes works. They really should be irrelevant, because as far as I know, they aren't being used anywhere else by my subclass.
Please, if anyone has any ideas, it is always appreciated. Even if you don't know the answer directly, but know some other source that may (which is unlikely, since I've scoured the net before this post), please point me in that direction, otherwise I may actually go insane working on this subclass.
Please, if anyone has any ideas, they are always appreciated. I may actually go insane if I never figure this out and really need to finish this subclass, so any help is greatly appreciated. Thank you.