0

iPad-iOS 5.1-Xcode 4.3.2

キーボードがポップアップするとき、UIImageViewのy原点を「x」だけ上にアニメーション化します。キーボードが下がるとき、同じ「x」だけ下にアニメーション化します。

つまり、キーボードがポップアップし、画像がXだけ上がり、キーボードが下がり、画像がxだけ下がりますが、同じ場所に表示されるわけではありません。あなたは60上昇し、60下降します、そしてあなたは同じ場所にいません!キーボードの外観と非表示の間で座標系が変化したかのように、さらに下にあります。それは絶対に私を夢中にさせます。なぜこれが起こるのか理解できません。

//add gesture recognizer when keyboard appears
-(void)keyboardWillShow:(NSNotification *) note {

    [self.view addGestureRecognizer:tapRecognizer];

    // Setup the animation
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3f];
    [UIView setAnimationCurve:UIViewAnimationOptionCurveEaseInOut];
    [UIView setAnimationBeginsFromCurrentState:YES];

    // The transform matrix: Logo Image

    CGAffineTransform moveLogo = CGAffineTransformMakeTranslation(0, -60);
    self.logoImageView.transform = moveLogo;

    // Commit the changes
    [UIView commitAnimations];  
}

//add gesture recognizer when keyboard appears
-(void)keyboardWillHide:(NSNotification *) note {

    [self.view removeGestureRecognizer:tapRecognizer];

    // Setup the animation
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3f];
    [UIView setAnimationCurve:UIViewAnimationOptionCurveEaseInOut];
    [UIView setAnimationBeginsFromCurrentState:YES];

    // The transform matrix: Logo Image

    CGAffineTransform moveLogo = CGAffineTransformMakeTranslation(0, 60);
    self.logoImageView.transform = moveLogo;

    // Commit the changes
    [UIView commitAnimations];  
}
4

3 に答える 3

4

これは、翻訳していないためです。CGAffineTransformMakeTranslationを使用すると、このオフセットを指定しないで、これらの座標を指定してくださいと言っています。言い換えると、make translationは、単位行列からの変換を提供します。必要な関数はCGAffineTransformTranslateです。これにより、変換が現在の変換に適用されます(最初の引数として渡されます)。

于 2012-05-15T23:29:31.363 に答える
0

変換プロパティは累積的ではありません。あなたは自分がしていると思うことをしていません。現在の変換からではなく、IDから新しい変換を計算しています。

それ以外の:

   CGAffineTransform moveLogo = CGAffineTransformMakeTranslation(0, 60);
    self.logoImageView.transform = moveLogo;

試す:

self.logoImageView.transform = CGAffineTransformIdentity;
于 2012-05-15T23:36:47.100 に答える
-1

Core Graphicsをいじくり回す代わりに、フレームやサイズなどの単純なビュープロパティをアニメーション化することをお勧めします。例えば:

[self.logoImageView.center = CGPointMake(self.logoImageView.center.x,
self.logoImageView.center.y + 60);

との間beginAnimationsでこれを行うcommitAnimations

于 2012-05-15T23:33:58.363 に答える