我正在尝试从屏幕底部(在标签栏的顶部)放置UIPickerView幻灯片,但似乎无法显示它。动画的实际代码来自Apple的示例代码项目之一(DateCell)。我从标签栏控制器下的第一个视图控制器(FirstViewController.m)调用此代码。
- (IBAction)showModePicker:(id)sender {
if (self.modePicker.superview == nil) {
[self.view.window addSubview:self.modePicker];
// size up the picker view to our screen and compute the start/end frame origin for our slide up animation
//
// compute the start frame
CGRect screenRect = [[UIScreen mainScreen] applicationFrame];
CGSize pickerSize = [self.modePicker sizeThatFits:CGSizeZero];
CGRect startRect = CGRectMake(0.0, screenRect.origin.y + screenRect.size.height, pickerSize.width, pickerSize.height);
self.modePicker.frame = startRect;
// compute the end frame
CGRect pickerRect = CGRectMake(0.0, screenRect.origin.y + screenRect.size.height - pickerSize.height, pickerSize.width, pickerSize.height);
// start the slide up animation
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
// we need to perform some post operations after the animation is complete
[UIView setAnimationDelegate:self];
self.modePicker.frame = pickerRect;
// shrink the vertical size to make room for the picker
CGRect newFrame = self.view.frame;
newFrame.size.height -= self.modePicker.frame.size.height;
self.view.frame = newFrame;
[UIView commitAnimations];
// add the "Done" button to the nav bar
self.navigationItem.rightBarButtonItem = self.doneButton;
}}
每当此动作通过位于UINavigationBar(全部位于FirstViewController下)的UIBarButtonItem触发时,都不会发生任何事情。有人可以提供一些建议吗?
答案 0 :(得分:0)
原来我错过了一个非常重要的事实,即UIPickerView已经在Interface Builder中定义了......在这样做之后连接插座一切正常!