繁体   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