搜尋此網誌

2012年9月27日 星期四

更新到ios6 畫面旋轉的問題解決


其實這篇很單純
如果要符合iOS 6
不需要改動程式其他部分只要加上

  1. -(NSUInteger)supportedInterfaceOrientations{  
  2.     return UIInterfaceOrientationMaskLandscape;  
  3. }  
  4.   
  5. - (BOOL)shouldAutorotate  
  6. {  
  7.     return YES;  
  8. }  

要怎麼轉動請改第一個supportedInterfaceOrientations

原文如下:
iOS 6的rotation改变了很多。先来看看官方的描述  http://www.bgr.com/2012/08/06/ios-6-beta-4-change-log-now-available/

2012年9月26日 星期三

UIViewController旋转方法详解



@interface UIViewController (UIViewControllerRotation)

//是否允许旋转
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation; 
// Override to allow rotation. Default returns YES only for UIInterfaceOrientationPortrait


// Notifies when rotation begins, reaches halfway point and ends.
//将开始旋转执行
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
//旋转完成后执行
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;

// Faster one-part variant, called from within a rotating animation block, for additional animations during rotation.
// A subclass may override this method, or the two-part variants below, but not both.
//旋转动画将开始时执行
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration__OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);

// Slower two-part variant, called from within a rotating animation block, for additional animations during rotation.
// A subclass may override these methods, or the one-part variant above, but not both.
//将在动画选择到一半时执行
- (void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
//完成动画旋转到一半时执行
- (void)didAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation; // The rotating header and footer views are offscreen.
//在第二个选择动话到一半时执行
- (void)willAnimateSecondHalfOfRotationFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration; // A this point, our view orientation is set to the new orientation.

在 Xcode 中採用橫向介面設計的方法


轉貼:http://furnacedigital.blogspot.tw/2011/06/xcode.html

 

橫向介面指的是 Landscape Left 或 Landspace Right 如上圖右,這類的應用很常在遊戲中被使用,下面將以 Xcode 4 為例,示範如何在設計介面時就使用橫向的方式來設計。

在開啟專案之後可以在 Target 中找到 Supported Device Orientations 支援裝置的方向的項目,在此項目中被選取(按下)的方向則代表有支援,由下圖可以得知此專案支援直立與左橫置。


2012年9月25日 星期二

(IOS)更改 app name


Change Complete Project Name

Menu > Project > Edit Active Target > Build tab
Select ‘All Configurations’ from Configuration.
Scroll down to the ‘Packaging’ group > Product Name
Double click it and enter the new name.
Build and run and the name has changed.

Change The Displayed Name

Changing the displayed name of the app (for instance if the full app name is too long to fit under the icon)
Open ApName_prefix.plist
Change the ‘Bundle Display Name’ entry.
The default is ‘${PRODUCT_NAME}’, overwrite this with the shorter name to be displayed.

How to Draw Pixel-Perfect iPhone Toolbar Icons

http://steveweller.com/articles/toolbar-icons/

[Note: I have created a companion article that covers tab bar icons. It includes an updated template with new guides and a new example project.]
Creating good-looking iPhone toolbar icons is definitely a challenge. The background must be transparent and the icon antialiased. It's also white, so you'd like to work in white against a dark background and have some sort of preview that you can reference. Unless you're a Photoshop or Illustrator jockey, it's hard to know where to start.

I create pixel-perfect icons for my iPhone apps using OmniGraffle, a toolbar icon template, and a simple workflow. You can buy OmniGraffle from Omni Group and get the rest here. Note that although I'm creating a bit-mapped PNG as the final output, I'm working with vector images. This gives me the freedom to adjust and tweak as needed for the best output.

Download the template. It contains an OmniGraffle 5.1 document and an example Xcode project that uses the UIToolbarItem icon.

關於UITabbar 圖片



  • 屬於 Bar  的有
    - Navigation bars
    - Toolbars
    - Tabbars
  • Style/Image 可透過
    - (id)initWithTitle:(NSString *)title image:(UIImage *)image tag:(NSInteger)tag;
    - (id)initWithTabBarSystemItem:(UITabBarSystemItem)systemItem tag:(NSInteger)tag;
  • Style
    typedef enum {
        UITabBarSystemItemMore,
        UITabBarSystemItemFavorites,
        UITabBarSystemItemFeatured,
        UITabBarSystemItemTopRated,
        UITabBarSystemItemRecents,
        UITabBarSystemItemContacts,
        UITabBarSystemItemHistory,
        UITabBarSystemItemBookmarks,
        UITabBarSystemItemSearch,
        UITabBarSystemItemDownloads,
        UITabBarSystemItemMostRecent,
        UITabBarSystemItemMostViewed,
    } UITabBarSystemItem;
  • TabBar icon 大小
    32 x 32 png 背景為透明。
  • TabBar icon 作圖,參考
    How to Draw Pixel-Perfect iPhone Toolbar Icons
    Generating icons for iPhone UITabBar
    tabbaritem的png無法顯示
  • 顯示圖片設定,實際顯示的圖片會便
    UIImage* aImage = [UIImage imageNamed:@"favorites.png"];
    [self.tabBarItem setImage:aImage];
  • 內建直接設定 badge,後面帶入 NSString
    [self.tabBarItem setBadgeValue:@"100"];
  • 承上面兩項,實際顯示的圖形會被系統再處理一次
    原本被選取時沒被選取時
    image
    32 x 32
    imageimage
  • 2012年9月23日 星期日

    evnet click view 點擊畫面的事件觸發


    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        [self performSegueWithIdentifier:@"LoginSegue" sender:nil];
    }


    You can use UIView subclass and handle touch event there. Methods to look at (defined inUIResponder):
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
    If you want to use "invisible" UIButton you should set its type to UIButtonTypeCustom - by default it will appear with no image and title and with transparent background. So technically it will be invisible to user but still be able to respond to all events.

    2012年9月19日 星期三

    2012年9月18日 星期二

    iOS中定时器NSTimer的使用


    1、初始化
    + (NSTimer *)timerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)yesOrNo;
    + (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)yesOrNo;
    注:不用scheduled方式初始化的,需要手动addTimer:forMode: 将timer添加到一个runloop中。
      而scheduled的初始化方法将以默认mode直接添加到当前的runloop中.

    2012年9月17日 星期一

    在使用模擬器時有聲音,但裝到ios device卻沒聲音




    MPMoviePlayer sound working in Simulators and ipad device, but not Working in iPhone Device


    http://stackoverflow.com/questions/9408211/mpmovieplayer-sound-working-in-simulators-and-ipad-device-but-not-working-in-ip

    http://stackoverflow.com/questions/5867341/how-to-turn-off-audio-in-mpmovieplayercontroller-iphone

    主要就是針對下面設定成NO




    useApplicationAudioSession


    [轉載] Objective C 字串連接 & 型別轉換




    /*字串連接*/
    在java裡面我們常常用到"+"來連接兩個字串 但在objective c似乎不是這樣用
    以下用一個例子解釋
    float weight=benefit2/7700;
    //將float轉成string
    NSString* Text = [[NSString alloc] initWithFormat:@"%f", weight];
    NSString* Text1=@"你會瘦";
    NSString* Text2=@"kg";
    //將三個字串連結在一起
    NSString *ConText = [NSString stringWithFormat:@"%@%@%@", Text1,Text, Text2];

    [IPHONE]在App Store上發佈程式



    程式終於編寫好了,這一回介紹應用程式的發佈流程。通過 App Store 將自己的程式向全世界公開。
    準備工作
    向 App Store 註冊自己的程式之前,需要準備以下的東西。

    57×57圖元的ICON
    512×512圖元的ICON (JPEG或TIFF格式)

    2012年9月16日 星期日

    检测iOS的网络可用性并打开网络设置


    要求程序能够检测网络可用性,并在没有网络可用的时候能够弹出对话框,并允许用户点击按钮打开网络设置。
    这个问题,我首先想到的就是用一个方法检测网络可用性,然后用UIApplicationopenURL方法打开某个特殊URL,就可以进入设置了。于是,我迅速地建了个测试项目,写了个简单的实现,如下:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    
    // 注意:这个方法仅对iOS 5.0.x有效
    + (BOOL) isNetworkAvailable { //Via Stackoverflow
        NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];
        NSURLRequest *request = [NSMutableURLRequest requestWithURL:url];
        NSHTTPURLResponse *response = nil;
        [NSURLConnection sendSynchronousRequest:request
                              returningResponse:&response error:NULL];
        return (response != nil);
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        if (![[self class] isNetworkAvailable]) {
            [[[UIAlertView alloc] initWithTitle:@"No network" message:@"No networkNetwork unavailable!!!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Settings", nil] show];
        }
    }
    
    - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
        if (buttonIndex != 0) {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=General&path=Network"]];
        }
    }
    

    编译运行之后,网络不可用倒是顺利提示了,但是我很杯具的发现,点了提示框里的“Settings”按钮之后完全没有反应。于是STFW,然后悲催的发现“特殊URL”在iOS 5.1里已经失效。多方搜索基于openURL的方法无果。


    2012年9月13日 星期四

    searchBar keybroad

    當點到keybroad外面時要怎麼將鍵盤消除

    方法一

    - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
        [searchBar resignFirstResponder];
        // Do the search...
    }


    方法二

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
       [self.view endEditing:YES];
    }
    

    2012年9月12日 星期三

    當鍵盤擋住輸入時


    方法一 移動畫面
    - (void) textFieldDidBeginEditing:(UITextField *)textField{

        [UIView beginAnimations:nil context:nil];

        [UIView setAnimationDuration:0.25];

        [self.view setFrame:CGRectMake(0, correctY, self.view.frame.size.width, self.view.frame.size.height)];

        [UIView commitAnimations];

    }
    correctY=-100向上移動100

    AFNetworking使用範例


    直接使用


    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlstr]];

    AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
          
        } failure:^(NSURLRequest *request, NSHTTPURLResponse *response,NSError *error, id JSON) {
            NSLog(@"error:%@,response:%@",error,response);
            
        }];
    [operation start];