所以我想要做的是這個視圖是讓我可以上下滑動UIView(menuView)進出屏幕。所以在故事板/ IB中,我放置了一個UIView並將其連接到文件所有者和所有爵士樂。然後我進入程序的下面的代碼。問題是當nib加載它時,並沒有把UIView放在應該放在第一位的地方,然後滑動不起作用。我試過用這個按鈕編程的方法,它工作正常。預先感謝您對此有任何幫助。可滑動的UIView菜單,響應UIGestureRecognizer
.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;
}
沒有任何工作。 「菜單視圖」仍然不會像編程時那樣滑動。 – nfoggia 2012-07-27 05:58:17