2014年1

1.強(qiáng)制應(yīng)用為橫屏的方法。
在view contronller中的實(shí)現(xiàn)

  • (NSUInteger)supportedInterfaceOrientations {
    //返回支持的方向?yàn)闄M屏
    return UIInterfaceOrientationMaskLandscape;
    }

  • (BOOL) shouldAutorotate {
    return YES;
    }

2.在storyboard中以橫屏方式編輯的方法。
選中某個(gè)View Contronller在右側(cè)邊欄中設(shè)置Orientation選項(xiàng),默認(rèn)為Inferred,設(shè)為Landscape。

3.攝像頭預(yù)覽圖層顯示的圖像方向設(shè)置的方法。
獲取AVCaptureVideoPreviewLayer的成員變量connection,調(diào)用它的setVideoOrientation函數(shù)。

4.設(shè)計(jì)單實(shí)例為什么要重寫allocWithZone。
實(shí)踐證明,使用alloc方法初始化一個(gè)類的實(shí)例的時(shí)候,默認(rèn)是調(diào)用了 allocWithZone 的方法。于是覆蓋allocWithZone方法的原因已經(jīng)很明顯了:為了保持單例類實(shí)例的唯一性,需要覆蓋所有會(huì)生成新的實(shí)例的方法,如果有人初始化這個(gè)單例類的時(shí)候不走[[Class alloc] init] ,而是直接 allocWithZone, 那么這個(gè)單例就不再是單例了,所以必須把這個(gè)方法也堵上。allocWithZone這個(gè)方法之所以存在,是歷史遺留原因。它的參數(shù)memory zone已經(jīng)被棄用了,只是歷史原因才保留這個(gè)接口。

5.計(jì)算GPS坐標(biāo),兩點(diǎn)間相對方向。
IPHONE實(shí)景導(dǎo)航開發(fā)總結(jié)(二):
http://chenweihuacwh.iteye.com/blog/549381
http://bbs.9ria.com/thread-212032-1-1.html

6.有無狀態(tài)欄時(shí)的屏幕大小。
//獲取沒有狀態(tài)欄的屏幕大小
CGRect appRect = [ UIScreen mainScreen ].applicationFrame;
//獲取屏幕大小
CGRect rx = [UIScreen mainScreen].bounds;
//獲取狀態(tài)欄的大小
CGRect rect = [[UIApplication sharedApplication] statusBarFrame];
注意:調(diào)試發(fā)現(xiàn)橫屏的時(shí)候,獲取的矩形坐標(biāo)還是和豎屏的坐標(biāo)系一樣,但是View的坐標(biāo)是橫平的坐標(biāo)系。

7.真機(jī)調(diào)試介紹。
http://my.oschina.net/joanfen/blog/167730

8.找不到libxml中的頭文件時(shí)的處理方法。
在工程Build Settings的設(shè)置中,的Search Paths項(xiàng)中的Header Search Paths中添加如下路徑:
/usr/include/libxml2
在用xmpp實(shí)現(xiàn)推送時(shí),添加完xmpp代碼后還需要在target屬性設(shè)置中的Build Phases中的Link Binary With Libraries中添加這兩個(gè)庫:libresolv.dylib和libxml2.dylib

9.啟動(dòng)圖片不能顯示的問題。
iPhone只能添加豎屏的啟動(dòng)圖片,所以在target的屬性設(shè)置中的General中的Deployment Info中的Device Orientation屬性必須有protrait這項(xiàng)。
xcode也有點(diǎn)bug,在不選protrait后運(yùn)行,再次選擇后再運(yùn)行還是不能顯示啟動(dòng)圖片,要單獨(dú)選這項(xiàng)運(yùn)行后才可以顯示。

10.狀態(tài)欄的顯示和隱藏。
當(dāng)info.plist中的key值View controller-based status bar appearance的值為NO時(shí)有效。
在application:didFinishLaunchingWithOptions:中:
[application setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];

11.ios發(fā)布證書申請過程。
http://my.oschina.net/joanfen/blog/133624

12.判斷實(shí)例是不是某個(gè)類的。例子,判斷reachability的實(shí)例。

  • (void) reachabilityChanged:(NSNotification )note
    {
    Reachability
    curReach = [note object];
    NSParameterAssert([curReach isKindOfClass:[Reachability class]]);
    [self updateInterfaceWithReachability:curReach];
    }
    NSParameterAssert是debug版本才會(huì)運(yùn)行的斷言。release版本不會(huì)運(yùn)行。

13.檢測網(wǎng)絡(luò)連結(jié)狀態(tài)的方法。
http://www.cnblogs.com/mrhgw/archive/2012/08/01/2617760.html
使用之前請從Apple網(wǎng)站下載示例:點(diǎn)此下載
然后將Reachability.h 和 Reachability.m 加到自己的項(xiàng)目中,并引用 SystemConfiguration.framework,就可以使用了。
14.上傳應(yīng)用的二進(jìn)制文件到apple。工程的info.plist設(shè)置
首要做的是在Target屬性Build Settings中的Code Signing把Identity都設(shè)置為 IOS Distribution。還有菜單打開product->把Run和Archive的Build Configuration設(shè)置為Release。
可以有兩種方法,一種是用菜單中Xcode->Open Developer Tool->Application loader,來上傳.app的zip包。zip包生成方法:Build Release版的應(yīng)用后,在xcode的Products文件下右鍵點(diǎn)應(yīng)用的.app文件Show in Finder,把到拷貝出來打包成zip。就可以用Application loader上傳了。
我用的是第二種方法,生成Archive,菜單Product->Archive。之后會(huì)自動(dòng)打開Organizer,也可以通過菜單Window->Organizer打開。在Organizer中選Archive頁面,在這里可以看到生成的Archive可以進(jìn)行Validate和Distribute的操作,我在Validate時(shí)出現(xiàn)了問題,提示1.找不到nib file 2.info.plist文件中不能同時(shí)有nib file 和stroyboard file兩個(gè)配置。我用的是stroybord所以刪除nib file那一項(xiàng)就可以了。在哪刪呢,原來info.plist配置文件指的就是target屬性中info那頁中的第一項(xiàng)Custom ios Target Properies。Validate(驗(yàn)證)通過后,就可以發(fā)布了Distribute。

15.自定義導(dǎo)航欄后退按鈕的問題。
在有導(dǎo)航欄的controler中可以用self.navigationItem 的方法獲取導(dǎo)航欄,navigationItem中的leftBarButtonItem和rightBarButtonItem是本級頁面上的BarButtonItem,而backBarButtonItem是下一級頁面上的BarButtonItem。并且這些都是custom的,就是是自定義的,所以默認(rèn)情況下都是nil。要新建一個(gè)UIBarButtonItem 賦值給它。示例如下:
UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"back" style:UIBarButtonItemStyleBordered target:self action:nil];
[self.navigationItem setLeftBarButtonItem:backItem];

16.實(shí)現(xiàn)以下方法時(shí)要注意要調(diào)用[super viewWillAppear:animated]; 不然會(huì)出現(xiàn)一些系統(tǒng)方法無效的問題,比如這個(gè)設(shè)置無效:self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to preserve selection between presentations.
//self.clearsSelectionOnViewWillAppear = NO;

  • (void)viewWillAppear:(BOOL)animated
    {
    [super viewWillAppear:animated];
    }
    簡單來說,就是不調(diào)用父類的這個(gè)函數(shù)的話,界面就不會(huì)刷新了。

17.Navigation的一些用法。
http://ios.9tech.cn/news/2013/1104/38423.html
UINavigationController是UIViewController的子類,同時(shí)因?yàn)槠渌膙iew controller是嵌入在navigation controller中的,所以UIViewController中有navigationController 和navigationItem 這兩個(gè)屬性。而導(dǎo)航條屬性navigationBar 則是在UINavigationController中的屬性。在view controller中可以這樣設(shè)置導(dǎo)航條的顏色:[self.navigationController.navigationBar setBarTintColor:[UIColor redColor]];也可以在AppDelegate.m文件中的方法didFinishLaunchingWithOptions:里面添加如下代碼來修改顏色:

1

[[UINavigationBar appearance] setBarTintColor:[UIColor yellowColor]];

這個(gè)是設(shè)置所有的導(dǎo)航條的顏色。
導(dǎo)航條上返回按鈕的顏色是設(shè)置UINavigationBar中的屬性,[self.navigationController.navigationBar setTintColor:[UIColor lightGrayColor]];
以下是查看有什么字體和設(shè)置標(biāo)題樣式的代碼。大部分是英文字體,只對英文有效。
//查找有什么字體
for(NSString *familyName in [UIFont familyNames])
{
NSLog(@"familyName = %@", familyName);

    for(NSString *fontName in [UIFont fontNamesForFamilyName:familyName])
    {
        NSLog(@"\tfontName = %@", fontName);
    }  
}
{//設(shè)置所有導(dǎo)航條的標(biāo)題的字體顏色,字體陰影,字體大小。
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];
shadow.shadowOffset = CGSizeMake(0, 1);
[[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0], NSForegroundColorAttributeName, shadow, NSShadowAttributeName,[UIFont fontWithName:@"HelveticaNeue-CondensedBlack" size:18.0], NSFontAttributeName, nil]];
}

18.狀態(tài)欄樣式的設(shè)置。
可以設(shè)置為黑色或是白色也可以設(shè)置為隱藏。有兩種方法來設(shè)置和info.plist中的key值View controller-based status bar appearance有關(guān),這個(gè)值默認(rèn)為YES,這時(shí)在每個(gè)view control中重載方法:
-(UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}

  • (BOOL)prefersStatusBarHidden
    {
    return YES;
    }
    第一個(gè)是設(shè)置黑白,但貌似沒有效果,有可能是蘋果的BUG吧。當(dāng)這個(gè)值為NO時(shí)可以如下設(shè)置:
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

19.ios開發(fā)之MPMoviePlayerController播放本地及網(wǎng)絡(luò)視頻方法
01

NSString *path=[[NSBundle mainBundle] pathForResource:@"stream0" ofType:@"mp4"];

02

NSURL *url=[[NSURL alloc] initFileURLWithPath:path];

03

self.rootPlayer=[[MPMoviePlayerController alloc] initWithContentURL:url];

04

self.rootPlayer.view.frame=CGRectMake(0, 0, 200, 200);

05

self.rootPlayer.movieSourceType=MPMovieSourceTypeFile;//本地文件播放要設(shè)置視頻資源為文件類型資源,若設(shè)置為stream 則會(huì)錯(cuò)誤

06

[self.rootPlayer prepareToPlay];

07

**if**(self.rootPlayer)

08

{

09

    [self.rootPlayer play];

10

}

11

[self.view addSubview:self.rootPlayer.view];

1

self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"http://125.76.230.133/cast/mp4/50-screen.mp4"]];

2

self.moviePlayer.movieSourceType=MPMovieSourceTypeStreaming;//網(wǎng)絡(luò)文件要設(shè)置為stream

3

[self.moviePlayer play];

4

self.moviePlayer.view.frame= CGRectMake(0, 0, 300, 300);

5

[self.view addSubview:self.moviePlayer.view];

PS:播放器的對象必須是self的一個(gè)屬性 ,否則播放5秒左右就會(huì)中斷。

20.iOS: FFmpeg編譯和使用問題總結(jié)
http://www.cnblogs.com/smileEvday/p/ffmpeg.html

21.用c分配比較大的內(nèi)存時(shí)的注意事項(xiàng)。
在棧上分配內(nèi)存有大小限制,比如char rgbBuffer[230400]; 如果超過這個(gè)大小很多的話,就會(huì)掛掉,有內(nèi)存訪問錯(cuò)誤,一般掛在函數(shù)開頭,可能是函數(shù)開始分配內(nèi)存的時(shí)候掛的。所以要在堆上動(dòng)態(tài)分配內(nèi)存像這樣:
const int maxImageSize = 192010803/2;
unsigned char rgbBuffer = malloc(maxImageSize2);
……
free(rgbBuffer);

22.在工程中部分文件使用或不使用ARC的方法。
點(diǎn)擊項(xiàng)目導(dǎo)航文件****--> ****選中****Targets--> ****選擇**** Build Phases --> ****展開****Compile Sources ****這個(gè)時(shí)候,我們看到第二列的名稱為:****Compiler Flags ****雙擊你所要使用****ARC****的文件,并輸入**** ****-fobjc-arc****,那么現(xiàn)在這個(gè)文件就可以在編譯時(shí)使用ARC機(jī)制進(jìn)行編譯了。同上,如果想讓使用****ARC****機(jī)制的代碼不使用****ARC****機(jī)制,只需要輸入**** ****-fno-objc-arc
23.UITableViewCell中的UIImageView的大小位置變化問題。
在table view controller中設(shè)置了UIImageView的image([cell.imageView setImage:[UIImage imageNamed:@"camera_online"]];)后,UIImageView的大小和位置都發(fā)生了變化,和原來storyboard中的不一樣了。旋轉(zhuǎn)屏幕之后又變?yōu)閟toryboard中的樣子。
解決方法是在UITableViewCell的子類中重寫方法:
-(void)layoutSubviews
{
//[super layoutSubviews];
//[self.imageView setFrame:CGRectMake(50, 10,29, 29)];
//self.imageView.contentMode = UIViewContentModeScaleAspectFit;
}
1.像這樣重寫什么都不做就會(huì)保持在storybord中的樣子。2.如果想在這里設(shè)置大小位置可以像第二句那樣,setFrame,且不寫第一句。3.奇怪的是如果寫了第一句調(diào)用父類的方法的話,問題依舊,所以不能調(diào)用父類的layoutSubviews。
以上的方法也不太對,如果不調(diào)父類的函數(shù),table view的分割線和箭頭就會(huì)不見了。更好的解決方法是在調(diào)用父類的方法前,設(shè)置image view的frame和storyboard中的大小位置一樣,如下:
[self.imageView setFrame:CGRectMake(38, 5,53, 53)];
[super layoutSubviews];
這樣就可以了,奇怪的是在測試中發(fā)現(xiàn)這個(gè)frame的大小和位置只要隨便的一個(gè)值就可以不用和storybord中的一樣也可以。結(jié)果顯示的是storyboard中的大小位置,不管怎么樣問題解決了。

23.1.后來的補(bǔ)充說明。可能和view的生命周期中何時(shí)設(shè)置storyboard中的view的位置大小有關(guān)。
http://mikixiyou.iteye.com/blog/1774351
視圖控制器類一共有四個(gè)方法可以重寫來實(shí)現(xiàn)視圖加載和展現(xiàn),分別是ViewWillAppear:,viewDidAppear:,viewDidLoad:,viewDidLayoutSubviews。其中viewDidLayoutSubviews方法是在iOS5.0系統(tǒng)中才開始提供的。
在viewDidAppear:和viewDidLayoutSubviews中,得到的frame的值就是storyboard中設(shè)置的值了,所以設(shè)置storyboard中的值是在viewDidLoad和ViewWillAppear之后,viewDidAppear和viewDidLayoutSubviews之前,所以要自定義storyboard中的view的大小和位置要在viewDidAppear和viewDidLayoutSubviews中設(shè)置,如果在之前的兩個(gè)方法中設(shè)置的話會(huì)被storyboard中的值重置,結(jié)束無效。

24.屏幕旋轉(zhuǎn)問題。
http://blog.csdn.net/jaywon/article/details/8208991
一般大家都知道是在view controller中重寫以下兩個(gè)方法:
-(BOOL)shouldAutorotate
{
return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
但系統(tǒng)調(diào)用的是根視圖控制器(rootViewControler)里的這兩個(gè)方法。當(dāng)view controller嵌入在navigation controller中的時(shí)候,self.window.rootViewController = navCtrl; 根視圖控制器就是navigation controller,所以我們要寫一個(gè)它的子類,在其中重寫這兩個(gè)方法。實(shí)現(xiàn)時(shí)可以統(tǒng)一控制所有視圖的旋轉(zhuǎn),也可以讓子視圖自己控制,像這樣:
//讓子視圖來決定是否旋轉(zhuǎn)

  • (BOOL)shouldAutorotate
    {
    return self.topViewController.shouldAutorotate;
    }
    //讓子視圖來決定旋轉(zhuǎn)方向
  • (NSUInteger)supportedInterfaceOrientations
    {
    return self.topViewController.supportedInterfaceOrientations;
    }

25.主動(dòng)要求屏幕旋轉(zhuǎn)問題。
網(wǎng)上提供了兩種方法:
1.設(shè)置設(shè)備的方向:(performSelector:withObject: 和直接執(zhí)行的區(qū)別是這個(gè)是運(yùn)時(shí)的,編譯時(shí)不會(huì)檢查)
//轉(zhuǎn)為橫屏
if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
[[UIDevice currentDevice] performSelector:@selector(setOrientation:)
withObject:(id)UIInterfaceOrientationLandscapeRight];
}
2.旋轉(zhuǎn)狀態(tài)欄等。
//設(shè)置狀態(tài)欄旋轉(zhuǎn)
[[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationLandscapeRight animated:YES];
CGFloat duration = [UIApplication sharedApplication].statusBarOrientationAnimationDuration;
//設(shè)置旋轉(zhuǎn)動(dòng)畫
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:duration];
//設(shè)置導(dǎo)航欄旋轉(zhuǎn)
self.navigationController.navigationBar.frame = CGRectMake(-204, 224, 480, 32);
self.navigationController.navigationBar.transform = CGAffineTransformMakeRotation(M_PI1.5);
//設(shè)置視圖旋轉(zhuǎn)
self.view.bounds = CGRectMake(0, -54, self.view.frame.size.width, self.view.frame.size.height);
self.view.transform = CGAffineTransformMakeRotation(M_PI
1.5);
[UIView commitAnimations];
我用的是第1種,但有錯(cuò)誤提示,在ARC的情況下不能把UIInterfaceOrientationLandscapeRight 這個(gè)參數(shù)(其實(shí)是long類型)轉(zhuǎn)為id(對像類型)。我用的解決方法是把這個(gè)代碼獨(dú)立寫在一個(gè)文件中,做為一個(gè)靜態(tài)方法。在要用的地方調(diào)用。這個(gè)文件可以設(shè)置為不用ARC的方式來編譯就可以通過了。

26.ios6.0之后的tableview下拉刷新。
原來試著在storyboard中添加,把table view control的refreshing屬性改為enabled,并把出現(xiàn)的refresh control連接到代碼中。但沒有效果。
所以用以下代碼添加refresh control

  • (void)viewDidLoad
    {
    ……
    //添加下拉刷新
    self.refreshControl = [[UIRefreshControl alloc]init];
    //self.refreshControl.tintColor = [UIColor blueColor];
    self.refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:@"下拉刷新"];
    [self.refreshControl addTarget:self action:@selector(RefreshViewControlEventValueChanged) forControlEvents:UIControlEventValueChanged];

}
//下拉刷新響應(yīng)
-(void)RefreshViewControlEventValueChanged
{
//開始下拉刷新的加載動(dòng)畫
[self.refreshControl beginRefreshing];
//網(wǎng)絡(luò)請求列表數(shù)據(jù)
EyesHttpRequest *httpRequest = [EyesHttpRequest sharedHttpRequestInstance];
httpRequest.delegate = self;
[httpRequest sendRequestGetCameraList];
}
//獲取到列表數(shù)據(jù)

  • (void)gotCameraList:(NSString*)strXml
    {
    ……
    //更新tableview中的數(shù)據(jù)
    [self.tableView reloadData];
    //停止下拉刷新的加載動(dòng)畫
    if(self.refreshControl.refreshing == YES)
    [self.refreshControl endRefreshing];
    }

27.讓View響應(yīng)點(diǎn)擊。
如果想讓storyboard上的view響應(yīng)點(diǎn)擊等事件,可以把view設(shè)置為UIControl類,它是view的子類,可以響應(yīng)控件的各種事件。
比如,可以在事件響應(yīng)中做關(guān)閉輸入法的操作。

  • (IBAction)touchDown:(UIControl *)sender
    {
    // 發(fā)送resignFirstResponder.用來收起輸入法
    [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
    }
    要響應(yīng)輸入法的return按鈕,是通過添加textField的Did End OnExti響應(yīng)來實(shí)現(xiàn)的,如下:
    //響應(yīng)輸入法的return按鈕
  • (IBAction)accountDidEndOnExit:(UITextField *)sender
    {
    //移到下一個(gè)輸入框進(jìn)行輸入
    [self.textFieldPassword becomeFirstResponder];
    }

//響應(yīng)輸入法的return按鈕

  • (IBAction)passwordDidEndOnExit:(UITextField *)sender
    {
    //關(guān)閉輸入法
    [sender resignFirstResponder];
    //執(zhí)行登錄按鈕
    [self.buttonLogin sendActionsForControlEvents:UIControlEventTouchUpInside];
    }

28.進(jìn)入設(shè)置界面。
if (UIApplicationOpenSettingsURLString != NULL) {
NSURL *appSettings = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:appSettings];
}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 1,Search Bar 怎樣去掉背景的顏色(storyboard里只能設(shè)置background顏色,可是發(fā)現(xiàn)cl...
    以德扶人閱讀 2,874評論 2 50
  • *7月8日上午 N:Block :跟一個(gè)函數(shù)塊差不多,會(huì)對里面所有的內(nèi)容的引用計(jì)數(shù)+1,想要解決就用__block...
    炙冰閱讀 2,717評論 1 14
  • 傳統(tǒng)意義上的設(shè)計(jì)(How it looks)往往不會(huì)成為一個(gè)項(xiàng)目中決定成敗的因素,而更多的是那些看不見的(How ...
    ConanXin閱讀 226評論 0 0
  • 二十四歲,眼前的路,它的確從獨(dú)木橋,變得越來越寬,越來越平坦,我只要往前走就可以。 24歲的我,喜歡沒心沒肺地過日...
    ConanXin閱讀 175評論 0 1
  • 前幾天在公司看到一篇文章,關(guān)于如何作弊玩游戲的。 今天終于看了內(nèi)容,發(fā)現(xiàn)應(yīng)該還不算太難,回去花個(gè)幾天爭取也實(shí)現(xiàn)一下...
    lisp閱讀 129評論 0 0

友情鏈接更多精彩內(nèi)容