iPad开发新手常见问题

iPad开发新手常见问题

kagula

2011-6-28

正文

Q1: 代码的组织

A: 主要的组织形式:由xib文件及其对应的hm文件组成一个窗口(结点),以某个结点作为根结点,开支散叶,形成倒挂的树。用户通过窗口和程序进行交互。窗口内至少有一个底视图(View),其它View可以拖放到这个底视图中形成复杂的可交互的窗口,用户通过View和具体代码交互。

 

Q2: 窗口(结点)如何加载另一个窗口(结点)

A: 联系方式有两种:

第一种静态连接:假设有两个xib结点,一个名为A,另一个名为BA要调用B。首先Axib文件里面添加View Controller,设置View Controller的属性为Bxib文件和BClass。第二,在A的源码中添加指向BIBOutlet。第三,通过拖放把两者之间联系起来。这个方法最大的缺点是,你的APP启动时不管你现在有没有用到B,都会被装载,占用内存,因此只适合窗口数量比较少的情况。

最后一种方法为动态连接:只在需要的时候加载,但是最大的缺点是你要自己release

弹出方式主要有三种:第一种,叠加视图,使用addSubView方法。

第二种,模式对话框方式弹出视图,由弹出者负责设置弹出窗口的大小,示例代码如下,。

-(IBAction)popupView:(id)sender

{       

         myModalViewController.modalPresentationStyle = UIModalPresentationFormSheet;

         myModalViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

         [self presentModalViewController:myModalViewController animated:YES];

         myModalViewController.view.superview.frame = CGRectMake(0,0,320,200);

         myModalViewController.view.superview.center = self.view.center;

}

第三种,无模式对话框方式弹出窗口,示例如下,使用了动态加载方式加载另一个窗口:

//@interface MyPopOverView : UIViewController

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

         if(![popoverController isPopoverVisible]){

                   // Popover is not visible

                   myPopOver = [[MyPopOverView alloc] initWithNibName:@"MyPopOverView" bundle:nil];

                   popoverController = [[UIPopoverController alloc] initWithContentViewController:myPopOver];

 

                   UITouch* touch = [touches anyObject];

                   CGPoint  location = [touch locationInView:self.view];

                   NSLog(@"location=%f,%f",location.x,location.y);

                   popoverController.popoverContentSize=CGSizeMake(320, 200); 

        

                   [popoverController presentPopoverFromRect:CGRectMake(location.x, location.y, 320, 200)

                                                                                                inView:self.view permittedArrowDirections:NO animated:YES];

         }else{

                   [popoverController dismissPopoverAnimated:YES];

         }

        

         [super touchesBegan:touches withEvent:event];

}

 

Q3:自定义列表框要注意的地方

A:自定义列表框主要有两种方法,建议继承UITableViewCell的方式新建类,参考文档[1]这里要注意的是Xib中的View中的元素要拉到View而不是File’Owner

 

Q4:为选词浮标添加菜单项

A:仅给出示例代码

//第一步

- (void)viewDidLoad {       

         UIMenuItem *menuItem = [[UIMenuItem alloc]initWithTitle:@"新的菜单项" action:@selector(infoButtonPressed:)];

         UIMenuController *menu = [UIMenuController sharedMenuController];

         [menu setMenuItems:[NSArray arrayWithObject:menuItem]];

         [menuItem release];

        

    [super viewDidLoad];

}

//第二步

//激发infoButtonPressed后,从txtView控件中选择的单词

-(void)infoButtonPressed:(id)sender

{

         NSString *selectedText = [txtView.text substringWithRange:txtView.selectedRange];

         NSLog(@"%@",selectedText);

        

         g_params = selectedText;

        

         myModalViewController.oneLabel.text = selectedText;

    [self popupView:sender];

}

 

Q5:UIScrollView的使用要注意的地方

A:[1]添加手势后,UIScrollViewcanCancelContentTouches 属性要设为 NO,如果你想取到UIScrollView里的UIButton控件的事件的话。[2]横屏竖屏切换后,最好把UIScrollViewzoomScale属性设为1.0   其它事项参考资料[2]

 

 

Q6:横屏竖屏幕切换

A:使用下面的示例来说明使用                           

//第一步:响应事件

-(void) willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation

                                                                                                                         duration:(NSTimeInterval)duration

{

         [self screentz];

}

-(void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation

                                                                                              duration:(NSTimeInterval)duration

{

         [self screentz];

}

//第二步:实现screentz

-(void)screentz

{

         UIInterfaceOrientation destorien=self.interfaceOrientation;

         if (destorien==UIInterfaceOrientationPortrait||destorien==UIInterfaceOrientationPortraitUpsideDown) {

                   tableView.frame=CGRectMake(0,64, 320, 640);

         }

         else {

                   tableView.frame=CGRectMake(0, 64, 320, 640);

         }       

}

 

 

Q7:隔断时间自动隐藏控件

A: 下面是示例代码

- (void)runToolbarHidingTimer;

{

         toolbarHidingTimer = [NSTimer scheduledTimerWithTimeInterval: 10.0f

                                                                                                                                     target: self

                                                                                                                                   selector: @selector(hideToolbarAnimated)

                                                                                                                                   userInfo: nil

                                                                                                                                    repeats: NO];

}

 

- (void)showToolbar

{

         [toolbarHidingTimer invalidate];

         toolbarHidingTimer = nil;

        

         self.toolbar.hidden=NO;

         [self.toolbar setAlpha:1.0];

}

 

- (void)hideToolbarAnimated

{

         toolbarHidingTimer = nil;        

        

         CGContextRef context = UIGraphicsGetCurrentContext();

        

         // Initialize Animation

         [UIView beginAnimations:nil context:context];

         [UIView setAnimationDuration:0.5f];

         [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

        

         [self.toolbar setAlpha:0.0];

         // Animation Settings

        

         [UIView commitAnimations];

}

 

 

参考文档:

[1]Custom UITableViewCells with Interface Builder

http://www.e-string.com/content/custom-uitableviewcells-interface-builder

[2]Using UIScrollView and UIGestureRecoginzer to create a custom interface - Part II

http://www.waynewbishop.com/code/uiscrollview/part2

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kagula086

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值