2011-07-13 12 views
1

私が作業しているnibファイルにUIViewコントロールがあります。そのUIViewでは、他のnibファイルを配置することができます。 iPadを回転させると、-(void)deviceOrientationChanged:(NSNotification *)note{メソッドが実行され、iPadが横向きまたは縦向きのモードに入ったかどうかに応じてUIViewのサイズが変更されます。サブクラス(UIViewコントロールにあるnibファイル)では、iPadがlandsapeモードまたはportraitモードにも関与しているかどうかを知る必要があります。UIViewフレームのサイズが変更されたときにメソッドを実行します。

enter image description here

緑色の矩形がUIViewの制御であり、Iは、別のXIBファイルが置かれた内部:ベローはUIViewの制御を含み、UIViewの制御が別のnibファイルを含むそのnibファイルを示す写真です。

私は同じ代理人- (void)deviceOrientationChanged:(NSNotification *)note{を配置しました。私がそれをするときの問題は、サブビューデリゲートが実行され、他のデリゲートが実行されないことがあることです。それは実際のiPadでのみ起こり、シミュレータでは起こりません。 iPadが風景モードに入ると、私は両方の代議員が実行されるようにしたいと思います。ほとんどの場合、これは問題ではありませんが、iPadをちょっと傾けると、ただ1人のデリゲートが実行されます。そのため、フレームのサイズが変更されたときに、サブクラスでメソッドを呼び出すことを考えていたのです。また、私は緑のペン先ファイルからメソッドを呼び出すことができることを知っていますが、これは約60のスライドがあるので、私はちょうどビューのdinamicalyを変更しているパワーポイントプレゼンテーションのようなものです。 C#では、リフレクションを使用して動的データ型のメソッドを呼び出すことができます。 iPhoneのために似たようなものがあれば私は知らない。

(私が働いているNIBファイルとUIVIEWコントロールのサブビュー)が同じ時間に実行されることを希望します。

答えて

0
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 
} 
関連する問題