iphone - iPhone中的 subview 动画

标签 iphone objective-c ios

我正在使用下面的代码来显示隐藏我的 subview :

    [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"

}}

如何在此代码中设置 subview Y 轴值,因为当 subview 出现在屏幕上时,它会隐藏我的屏幕标题栏而且我正在使用按钮来显示/隐藏 subview ,我还想为该按钮设置动画,以便当单击按钮,按钮的位置也应沿 Y 轴更改。

这是我想要的截图

enter image description here

enter image description here

最佳答案

尝试将您的标题 View 放在 MainView 的前面:

     [self.view bringSubviewToFront:headerView];

而图像按钮动画你可以这样做:
[UIView animateWithDuration:1.0 animations:^{
    CGFloat degrees = 180;
    CGAffineTransform transform = 
    CGAffineTransformMakeRotation(degrees/180 * 3.14);
    imageButton.transform = transform;

}];

关于iphone - iPhone中的 subview 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8871698/

相关文章:

ios - 将 NSMutableArray 保存到文件

ios - UIButton 重叠并意外隐藏在 UITableViewCell 中

ios - 如何单独为 iPhone X 设备设置约束

iPhone/iPad 应用程序未出现在 iPad 应用程序商店中

ios - 在 xcode 中分离目标的预处理器指令

objective-c - 在 objective-c 中是否有一些我们可以用来设置断点的 no op 操作

ios - 如何在 UIWebView 或 WKWebView 中播放 facebook 视频

ios - UIView设置约束

iphone - 为什么我调整后的 OpenGL ES 2.0 模板在 iPad 上的帧速率如此之慢?

ios - 是否可以对 Swift 协议(protocol)进行哈希处理?