iPhone开发笔记2

一、概述

既然是使用object-c,那么入口就和c语言一样,是main函数,可以在新创建的工程中看到一个main.m,这里就是入口了。和c语言的入口区别在哪里呢?UIApplicationMain。

UIApplicationMain函数的定义可以得知:

int UIApplicationMain (
   int argc,
   char *argv[],
   NSString *principalClassName,
   NSString *delegateClassName
);

Parameters
argc
The count of arguments in argv; this usually is the corresponding parameter to main.
argv
A variable list of arguments; this usually is the corresponding parameter to main.
principalClassName
The name of the UIApplication class or subclass. If you specify nil, UIApplication is assumed.
delegateClassName
The name of the class from which the application delegate is instantiated. If principalClassName designates a subclass of UIApplication, you may designate the subclass as the delegate; the subclass instance receives the application-delegate messages. Specify nil if you load the delegate object from your application’s main nib file.
Return Value
Even though an integer return type is specified, this function never returns. When users exits an iPhone application by pressing the Home button, the application moves to the background.

前面两个参数都是c语言中很熟悉的了,就不用介绍了,主要谈谈后面两个参数。

principalClassName就是UIApplication类名或者其子类名,如果为nil,默认就是UIApplication。

delegateClassName指的是delegate的类名,如果为nil,就是指你的主nib文件中指定的delegate类名。一般在一个工程中,main函数里面的东西都不用改,因为在xcode创建工程的时候全部都帮你设计好了,你需要改变的主要在你的一个plist文件中,名字就是xxx-info.plist。里面的Main nib file base name就是当前的主nib文件名,默认都是MainWindow。Bundle display name就是当应用程序装载到手机上图标所显示的名字。Icon file就是指定的app icon。还有一个比较重要的东西就是Bundle identifier,这个标志是比较重要的,用来确认手机中程序的独一无二性。

二、启动画面和app icon

接着谈谈iphone的启动画面和app icon吧。

前面提到的icon file就可以更改app icon了。还有种方法更简便,就是直接把指定尺寸的图片放进工程就行了,具体实现懒得写了,直接拷贝一份资料吧:

iOS设备现在有三种不同的分辨率:

iPhone 320x480,

iPhone 4 640x960,

iPad 768x1024。

以前程序的启动画面(图片)只要准备一个Default.png就可以了,但是现在变得复杂多了。

如果一个程序,既支持iPhone又支持iPad,那么它需要包含下面几个图片:

Default-Portrait.png iPad专用竖向启动画面 768x1024或者768x1004

Default-Landscape.png iPad专用横向启动画面 1024x768或者1024x748

Default-PortraitUpsideDown.png iPad专用竖向启动画面(Home按钮在屏幕上面),可省略 768x1024或者768x1004

Default-LandscapeLeft.png iPad专用横向启动画面,可省略 1024x768或者1024x748

Default-LandscapeRight.png iPad专用横向启动画面,可省略 1024x768或者1024x748

Default.png iPhone默认启动图片,320x480或者320x460

Default@2x.png iPhone4启动图片640x960或者640x920

为了在iPad上使用上述的启动画面,你还需要在info.plist中加入

key: UISupportedInterfaceOrientations。

同时,加入值

UIInterfaceOrientationPortrait

UIInterfaceOrientationPortraitUpsideDown

UIInterfaceOrientationLandscapeLeft

UIInterfaceOrientationLandscapeRight。

以上就是启动画面,那么app icon呢,还是拷贝一份资料吧,如下:

Icon sizes for iOS (iPhone, iPad and iPod touch)

Here are the icon sizes from the iOS Human Interface Guidelines.

iOS icon sizes

DescriptionSize for iPhone and iPod touchSize for iPad
Application icon (required)57x57
114x114 (iPhone4)
72x72
App Store icon (required)512x512512x512
Small icon (recommended)29x29
58x58 (iPhone4)
50x50 for Spotlight search results
29x29 for Settings
 

二、table view

以后详谈吧,就说说主要的方式,经过一个多月的总结,其实iphone的类都很齐全,基本就是使用delegate的方式来使用的。


三、动画

目前我总结的有3种。

1、直接使用uiview类的

+ (void)beginAnimations:(NSString *)animationID context:(void *)context;  // additional context info passed to will start/did stop selectors. begin/commit can be nested
+ (void)commitAnimations; 

例子:

官方的一段代码:

[UIView beginAnimations:@"animationID" context:nil];
    [UIView setAnimationDuration:0.5f];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationRepeatAutoreverses:NO];
    UIButton *theButton = (UIButton *)sender;
    switch (theButton.tag) {
        case 0:
            [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];//oglFlip, fromLeft
            break;
        case 1:
            [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];//oglFlip, fromRight     
            break;
        case 2:
            [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
            break;
        case 3:
            [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
            break;
        default:
            break;
    }
    [self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];
    [UIView commitAnimations];

2、使用CATransition

其中又可以分成两种:

(1)public

CATransition *animation = [CATransition animation];
    //animation.delegate = self;
    animation.duration = 0.5f;
    animation.timingFunction = UIViewAnimationCurveEaseInOut;
    animation.fillMode = kCAFillModeForwards;
    //animation.removedOnCompletion = NO;
    
    UIButton *theButton = (UIButton *)sender;
    /*
     kCATransitionFade;
     kCATransitionMoveIn;
     kCATransitionPush;
     kCATransitionReveal;
     */
    /*
     kCATransitionFromRight;
     kCATransitionFromLeft;
     kCATransitionFromTop;
     kCATransitionFromBottom;
     */
    switch (theButton.tag) {
        case 0:
            animation.type = kCATransitionPush;
            animation.subtype = kCATransitionFromTop;
            break;
        case 1:
            animation.type = kCATransitionMoveIn;
            animation.subtype = kCATransitionFromTop;
            break;
        case 2:
            animation.type = kCATransitionReveal;
            animation.subtype = kCATransitionFromTop;
            break;
        case 3:
            animation.type = kCATransitionFade;
            animation.subtype = kCATransitionFromTop;
            break;
        default:
            break;
    }
    
    [self.view.layer addAnimation:animation forKey:@"animation"];

(2)private

CATransition *animation = [CATransition animation];
    animation.delegate = self;
    animation.duration = 0.5f * slider.value;
    animation.timingFunction = UIViewAnimationCurveEaseInOut;
    animation.fillMode = kCAFillModeForwards;
    animation.endProgress = slider.value;
    animation.removedOnCompletion = NO;
    
    UIButton *theButton = (UIButton *)sender;
    
    switch (theButton.tag) {
        case 0:
            animation.type = @"cube";//---
            break;
        case 1:
            animation.type = @"suckEffect";//103
            break;
        case 2:
            animation.type = @"oglFlip";//When subType is "fromLeft" or "fromRight", it's the official one.
            break;
        case 3:
            animation.type = @"rippleEffect";//110
            break;
        case 4:
            animation.type = @"pageCurl";//101
            break;
        case 5:
            animation.type = @"pageUnCurl";//102
            break;
        case 6:
            animation.type = @"cameraIrisHollowOpen ";//107
            break;
        case 7:
            animation.type = @"cameraIrisHollowClose ";//106
            break;
        default:
            break;
    }
    
    [self.view.layer addAnimation:animation forKey:@"animation"];


参考资料:

http://www.visualpharm.com/articles/icon_sizes.html

http://news.wangmeng.cn/detailNews/2984-iphone-start-page-default-png

以及官方代码示例UIViewDemo 2。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值