我有一个UIScrollView
菜单,可以通过激活UIButton
在视口上方和下方移动。问题是,当我按下按钮以使UIScrollView
菜单上下移动时,按钮只会停留在一个位置。我希望UIButton
在UIScrollView
菜单激活时将高于。这是它的样子,“开放”是UIButton
:
以下是来自viewcontroller.m
和UIScrollView
的{{1}}的动画代码。
UIButton
我希望“打开”按钮位于绿色#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize scrollView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
draw1 = 0;
scrollView.frame = CGRectMake(0, 300, 480, 55);
[scrollView setContentSize:CGSizeMake(480, 55)];
openMenu.frame = CGRectMake(220, 270, 60, 30);
}
- (IBAction)OpenMenu:(id)sender {
if (draw1 ==0) {
draw1 = 1;
[UIView animateWithDuration:0.5
delay:0.0
options: UIViewAnimationOptionCurveEaseOut
animations:^{
scrollView.frame = CGRectMake(0, 1000, 568, 200);
openMenu.frame = CGRectMake(220, 200, 60, 30);
}
completion:^(BOOL finished){
NSLog(@"Done!");
}];
} else {
draw1 = 0;
[UIView animateWithDuration:0.5
delay:0.0
options: UIViewAnimationOptionCurveEaseOut
animations:^{
scrollView.frame = CGRectMake(0, 300, 568, 200);
openMenu.frame = CGRectMake(220, 270, 60, 30);
}
completion:^(BOOL finished){
NSLog(@"Done!");
}];
}
}
上方(不在其上方),我该怎么做?
答案 0 :(得分:1)
好的,将openMenu.frame = <frame>
更改为openMenu.layer.frame = <frame>
您的代码应该是这样的 设置初始帧添加此方法
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
draw1 = 1;
openMenu.layer.frame = CGRectMake(self.view.center.x - 30, self.view.frame.size.height - 80, 60, 30);
}
- (IBAction)OpenMenu:(id)sender {
if (draw1 ==0) {
draw1 = 1;
[UIView animateWithDuration:0.5
delay:0.0
options: UIViewAnimationOptionCurveEaseOut
animations:^{
scrollView.frame = CGRectMake(0, 1000, 568, 200);
openMenu.layer.frame = CGRectMake(self.view.center.x - 30, self.view.frame.size.height - 80, 60, 30);
}
completion:^(BOOL finished){
NSLog(@"Done!");
}];
} else {
draw1 = 0;
[UIView animateWithDuration:0.5
delay:0.0
options: UIViewAnimationOptionCurveEaseOut
animations:^{
scrollView.frame = CGRectMake(0, 300, 568, 200);
openMenu.layer.frame = CGRectMake(self.view.center.x - 30, 270, 60, 30);
}
completion:^(BOOL finished){
NSLog(@"Done!");
}];
}
}