簡體   English   中英

iPhone中的子視圖動畫

[英]subview animation in iPhone

我正在使用下面的代碼來顯示隱藏我的子視圖:

    [self.view addSubview:selectorView];
[selectorView setFrame:CGRectOffset([selectorView frame], 0, -selectorView.frame.size.height)];
viewVisible = NO;

- (IBAction)onButtonClick:(id)sender {
[self showHideView]; // Show and hide our imageView in an animated fashion}

- (void)showHideView {  
if (viewVisible) { // If our imageView is on screen hide the view
    [UIView beginAnimations:@"animateImageOff" context:NULL]; // Begin animation
    [selectorView setFrame:CGRectOffset([selectorView frame], 0, -selectorView.frame.size.height)]; // Move imageView off screen
    [UIView commitAnimations]; // End animations
    viewVisible = NO;
    [showHideButton setTitle:@"Show" forState:UIControlStateNormal]; // Change button title to "Show"
} else { // if our imageView is off screen show the view
    [UIView beginAnimations:@"animateImageOn" context:NULL]; // Begin animation
    [selectorView setFrame:CGRectOffset([selectorView frame], 0, selectorView.frame.size.height)]; // Move imageView on screen
    [UIView commitAnimations]; // End animations
    viewVisible = YES;
    [showHideButton setTitle:@"Hide" forState:UIControlStateNormal]; // Change button title to "Hide"

}}

我如何在此代碼中設置子視圖的Y軸值,因為當子視圖出現在屏幕上時,它會隱藏我的屏幕標題欄,而且我正在使用一個按鈕來顯示/隱藏子視圖,所以我還想對該按鈕進行動畫處理,以便單擊按鈕后,按鈕的位置也應沿Y軸更改。

這是我想要的屏幕截圖

在此處輸入圖片說明

在此處輸入圖片說明

嘗試將您的標題視圖放在MainView的前面:

     [self.view bringSubviewToFront:headerView];

和圖像按鈕動畫,您可以執行以下操作:

[UIView animateWithDuration:1.0 animations:^{
    CGFloat degrees = 180;
    CGAffineTransform transform = 
    CGAffineTransformMakeRotation(degrees/180 * 3.14);
    imageButton.transform = transform;

}];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM