Execute method when UIView frame changes its size iPhone iPad
I have a UIView control in the nib file that I am working on. In that UIView I am able to place other nib files. When the iPad is rotated the -(void)deviceOrientationChanged:(NSNotification *)note{
method gets executed and I resize the UIView depending if the iPad entered landscape or portrait mode. In the subclass (the nib file that is in the UIView controll) I need to know if the iPad enteres landsape mode or portrait mode as well. Bellow is a picture demonstrating the nib file that contains a UIView control and that UIView control containing another nib file:
green rectangle is a UIView control and inside I have placed another xib file.
So I placed the same delegate - (void)deviceOrientationChanged:(NSNotification *)note{
. the problem when I do that is that sometimes the subview delegate get's executed and the other delegate does not. That only happens on the real iPad and not in the simulator. If the iPad enters landscape mode I would like both delegates to get executed. Most of the time this is not a problem but if I tilt the iPad a little bit just one delegate will get executed. That's why I was thinking about calling a method in the subclass when its frame get's resized. Also I know that I can call a method from the green nib fil开发者_运维技巧e but this is like a powerpoint presentation where there are about 60 slides therefore I am just changing the view's dinamicaly. In c# I would be able to call a method of a dynamic data type using reflection. I don't konw if something similar exist for the iPhone.
IN SHORT I WANT BOTH DELEGATES (THE ONE FROM THE NIB FILE THAT I AM WORKING WITH AND THE SUBVIEW OF THE UIVIEW CONTROL) TO GET EXECUTED AT THE SAME TIME.
BOOL myBool;
// this function get's called when the orientation of the ipad changes
- (void)deviceOrientationChanged2:(NSNotification *)note{
// do not call this method untill other method finish executing it...
if(myBool==YES)
return;
myBool=YES;
// wait half a second then call handlerTimer method
NSTimer *timer;
timer = [NSTimer scheduledTimerWithTimeInterval: (.5)
target: self
selector: @selector(handleTimer:)
userInfo: nil
repeats: NO];
}
-(void) handleTimer:(NSTimer*)theTimer{
// this method just uses a diferent image on landscape mode compared to portrait mode
// if the image is in landscapemode for example and it is the one for landscape then don't change its alpha the image will not be changed
if( (imgTextbox.image == [UIImage imageNamed:@"introPaswordVertical.png"] && [super view].frame.size.width>800) || (imgTextbox.image == [UIImage imageNamed:@"introPasswordHorizontal.png"] && [super view].frame.size.width<800))
{
imgTextbox.alpha = 0;
}
// if the super view is in portrait mode then place the vertical image
if([super view].frame.size.width<800)
{
imgTextbox.image = [UIImage imageNamed:@"introPaswordVertical.png"];
}
else // otherwise place the otherone
{
imgTextbox.image = [UIImage imageNamed:@"introPasswordHorizontal.png"];
}
// animate the image
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.55];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
imgTextbox.alpha = 1;
[UIView commitAnimations];
myBool=NO; // enable deviceOrientationChanged2 to be called again
}
精彩评论