所以我试图用这个视图做的就是让它让我可以上下滑动 UIView (menuView) 进出屏幕。所以在 storyboard/IB 中我放置了一个 UIView 并将它连接到文件所有者和所有爵士乐。然后我进入程序下面的代码。问题是,当笔尖加载时,它没有将 UIView 放在它应该放在首位的位置,然后滑动不起作用。我尝试了这种用按钮编程的方法,效果很好。提前感谢您在该主题上可能获得的任何帮助。
.h 文件
UIView *menuView;
}
@property (strong, nonatomic) IBOutlet UIView *menuView;
.m 文件
@synthesize menuView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)];
[swipeGesture setDirection:UISwipeGestureRecognizerDirectionDown];
[self.view addGestureRecognizer:swipeGesture];
menuView = [[UIView alloc] initWithFrame:CGRectMake(0, -80, 320, 80)];
[menuView setFrame:CGRectMake(0, -80, 320, 80)];
[self.view addSubview:menuView];
}
-(void)swipe:(UISwipeGestureRecognizer*)sender {
[UIView animateWithDuration:0.5 animations:^{
[menuView setFrame:CGRectMake(0, 0, 320, 80)];
}];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}