【iOS-Cocos 2 dゲーム開発の16】ローカル通知(UILocalNotification)の追加とシステムコンポーネントのスクロールビューの追加!【2011年11月15日更新】

15159 ワード

    Himi   ,          :
   【  GameDev  】     : http://www.himigame.com/iphone-cocos2d/492.html


-------------【11 28         Cocos2d       BUG】--------
【iOS-Cocos2d      】 cocos2d   /      ,   View       View         【11 28         Cocos2d       BUG】!

 


               :                  ,                     ~       ~  ~   ;

           Himi              :    Cocos2d   UILocalNotification     ,        UIScrollViewiOS            ;
            UILocalNotification               ,    ,                      ;          :
                cocos2d   ,                           ;          AppDelegate.m    applicationDidFinishLaunching ,    :
             
[cpp] view plaincopyprint?- (void) applicationDidFinishLaunching:(UIApplication*)application 
{  
    ...  
    application.applicationIconBadgeNumber = 0;//          =0(  )   
    [[UIApplication sharedApplication] cancelAllLocalNotifications];//          
    //------  ;   
    UILocalNotification *notification=[[UILocalNotification alloc] init];   
    if (notification!=nil) {//               
        notification.fireDate=[NSDate dateWithTimeIntervalSinceNow:kCFCalendarUnitDay];//             
        notification.repeatInterval=kCFCalendarUnitDay;//          
        notification.timeZone=[NSTimeZone defaultTimeZone];  
        notification.alertBody=@" ,    ,   ?";//          
        notification.applicationIconBadgeNumber=1; //              
        notification.soundName= UILocalNotificationDefaultSoundName;//           
        notification.alertAction = NSLocalizedString(@"    !", nil);  //          
        [[UIApplication sharedApplication]   scheduleLocalNotification:notification]; 
    }   
 ...  
}  
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
    ...
    application.applicationIconBadgeNumber = 0;//          =0(  )
    [[UIApplication sharedApplication] cancelAllLocalNotifications];//       
    //------  ;
    UILocalNotification *notification=[[UILocalNotification alloc] init]; 
    if (notification!=nil) {//            
        notification.fireDate=[NSDate dateWithTimeIntervalSinceNow:kCFCalendarUnitDay];//           
        notification.repeatInterval=kCFCalendarUnitDay;//       
        notification.timeZone=[NSTimeZone defaultTimeZone];
        notification.alertBody=@" ,    ,   ?";//       
        notification.applicationIconBadgeNumber=1; //           
        notification.soundName= UILocalNotificationDefaultSoundName;//        
        notification.alertAction = NSLocalizedString(@"    !", nil);  //        
        [[UIApplication sharedApplication]   scheduleLocalNotification:notification];
    } 
 ...
} 
             Himi               ,             ,              0,     0            ;
                          ,iOS        :
  
[cpp] view plaincopyprint?enum {  
    kCFCalendarUnitEra = (1UL << 1),  
    kCFCalendarUnitYear = (1UL << 2),  
    kCFCalendarUnitMonth = (1UL << 3),  
    kCFCalendarUnitDay = (1UL << 4),  
    kCFCalendarUnitHour = (1UL << 5),  
    kCFCalendarUnitMinute = (1UL << 6),  
    kCFCalendarUnitSecond = (1UL << 7),  
    kCFCalendarUnitWeek = (1UL << 8) /* CF_DEPRECATED(10_4, 10_7, 2_0, 5_0) */,  
    kCFCalendarUnitWeekday = (1UL << 9),  
    kCFCalendarUnitWeekdayOrdinal = (1UL << 10),  
#if MAC_OS_X_VERSION_10_6 <= MAC_OS_X_VERSION_MAX_ALLOWED || __IPHONE_4_0 <= __IPHONE_OS_VERSION_MAX_ALLOWED  
    kCFCalendarUnitQuarter = (1UL << 11),  
#endif   
#if MAC_OS_X_VERSION_10_7 <= MAC_OS_X_VERSION_MAX_ALLOWED || __IPHONE_5_0 <= __IPHONE_OS_VERSION_MAX_ALLOWED  
    kCFCalendarUnitWeekOfMonth = (1UL << 12),  
    kCFCalendarUnitWeekOfYear = (1UL << 13),  
    kCFCalendarUnitYearForWeekOfYear = (1UL << 14),  
#endif   
};  
enum {
 kCFCalendarUnitEra = (1UL << 1),
 kCFCalendarUnitYear = (1UL << 2),
 kCFCalendarUnitMonth = (1UL << 3),
 kCFCalendarUnitDay = (1UL << 4),
 kCFCalendarUnitHour = (1UL << 5),
 kCFCalendarUnitMinute = (1UL << 6),
 kCFCalendarUnitSecond = (1UL << 7),
 kCFCalendarUnitWeek = (1UL << 8) /* CF_DEPRECATED(10_4, 10_7, 2_0, 5_0) */,
 kCFCalendarUnitWeekday = (1UL << 9),
 kCFCalendarUnitWeekdayOrdinal = (1UL << 10),
#if MAC_OS_X_VERSION_10_6 <= MAC_OS_X_VERSION_MAX_ALLOWED || __IPHONE_4_0 <= __IPHONE_OS_VERSION_MAX_ALLOWED
 kCFCalendarUnitQuarter = (1UL << 11),
#endif
#if MAC_OS_X_VERSION_10_7 <= MAC_OS_X_VERSION_MAX_ALLOWED || __IPHONE_5_0 <= __IPHONE_OS_VERSION_MAX_ALLOWED
 kCFCalendarUnitWeekOfMonth = (1UL << 12),
 kCFCalendarUnitWeekOfYear = (1UL << 13),
 kCFCalendarUnitYearForWeekOfYear = (1UL << 14),
#endif
};                :
                    


       

 

                 iOS5        ,                    , iOS5             ,                ~
         OK,          ,  easy;       cocos2d   UIScrollView;
          UIScrollView  ,    ,Android     ,        ,                           、      ,  Himi       cocos2d   UIScrollView                  ;
          :         cocos2d              《【Cocos2d      】 cocos2d   /      ,   View       View         !》     ,      :
                 cocos2d  ,            MyView(UIViewController)   ,   MyView.xib      label ScrollView   ;
             :
            


               MyView.h, MyView.m , MyView.h     :
          
[cpp] view plaincopyprint?@interface MyView : UIViewController{ 
    IBOutlet UIScrollView *scrollView;  
}  
@property(nonatomic,retain)IBOutlet UIScrollView *scrollView;  
@end  
@interface MyView : UIViewController{
    IBOutlet UIScrollView *scrollView;
}
@property(nonatomic,retain)IBOutlet UIScrollView *scrollView;
@end

  .h       UIScrollView   UIScrollViewDelegate  , IBOutlet  ,   xib    UIScrollView     scrollView;


             MyView.m       :
         1.        :
[cpp] view plaincopyprint?@synthesize scrollView; 
@synthesize scrollView;         2. - (void)viewDidLoad{}       :
[cpp] view plaincopyprint?- (void)viewDidLoad  
{  
    [super viewDidLoad];  
    //  view    
    scrollView.delegate = self;  
    scrollView.scrollEnabled = YES;   
    scrollView.contentSize = CGSizeMake(100, 249);//            
    // Do any additional setup after loading the view from its nib.   
}  
- (void)viewDidLoad
{
    [super viewDidLoad];
    //  view 
    scrollView.delegate = self;
    scrollView.scrollEnabled = YES; 
    scrollView.contentSize = CGSizeMake(100, 249);//         
    // Do any additional setup after loading the view from its nib.
}
      MyView.m    :
[cpp] view plaincopyprint?//   
//  MyView.m   
//  ScrollViewByHimi   
//   
//  Created by      on 11-10-22.   
//  Copyright (c) 2011  __MyCompanyName__. All rights reserved.   
//   
  
#import "MyView.h"   
  
@implementation MyView  
@synthesize scrollView;  
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{  
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];  
    if (self) {  
        // Custom initialization   
    }  
    return self;  
}  
  
- (void)didReceiveMemoryWarning  
{  
    // Releases the view if it doesn't have a superview.   
    [super didReceiveMemoryWarning];  
      
    // Release any cached data, images, etc that aren't in use.   
}  
  
#pragma mark - View lifecycle   
  
- (void)viewDidLoad  
{  
    [super viewDidLoad];  
    //  view    
    scrollView.delegate = self;  
    scrollView.scrollEnabled = YES;   
    scrollView.contentSize = CGSizeMake(100, 249);//            
    // Do any additional setup after loading the view from its nib.   
}  
  
- (void)viewDidUnload  
{  
    [super viewDidUnload];  
    // Release any retained subviews of the main view.   
    // e.g. self.myOutlet = nil;   
}  
  
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{  
    // Return YES for supported orientations   
    return (interfaceOrientation == UIInterfaceOrientationPortrait);  
}  
  
@end  
//
//  MyView.m
//  ScrollViewByHimi
//
//  Created by      on 11-10-22.
//  Copyright (c) 2011  __MyCompanyName__. All rights reserved.
//

#import "MyView.h"

@implementation MyView
@synthesize scrollView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    //  view 
    scrollView.delegate = self;
    scrollView.scrollEnabled = YES; 
    scrollView.contentSize = CGSizeMake(100, 249);//         
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

       OK,      ,      :
               

           ScrollView     ,ScrollView        ,           xib  ScrollView       ;


                    ScrollView          :
          HelloWorldLayer.m  init       view          :
[cpp] view plaincopyprint?[self schedule:@selector(viewAddPointY) interval:0.03];// 0.03     viewAddPointY   
[self schedule:@selector(viewAddPointY) interval:0.03];// 0.03     viewAddPointY           viewAddPointY   Himi      ,    :
[cpp] view plaincopyprint?-(void)viewAddPointY{  
    view.scrollView.contentOffset=ccpAdd(view.scrollView.contentOffset, ccp(0,0.5));// UIScrollView            0.5    
    //view.scrollView.contentSize.height :  UIScrollView      
    if(view.scrollView.contentOffset.y>=view.scrollView.contentSize.height){  
        view.scrollView.contentOffset=ccp(0,-view.scrollView.frame.size.height); 
    }  
}  
-(void)viewAddPointY{
    view.scrollView.contentOffset=ccpAdd(view.scrollView.contentOffset, ccp(0,0.5));// UIScrollView            0.5  
    //view.scrollView.contentSize.height :  UIScrollView   
    if(view.scrollView.contentOffset.y>=view.scrollView.contentSize.height){
        view.scrollView.contentOffset=ccp(0,-view.scrollView.frame.size.height);
    }
}
          :


                  


        :  Xcode 4.2      iOS5    ,                    UIScrollView               ,           ,Himi        ~
 
        ,     HelloWorldLayer.h  HelloWorldLayer.m      ,                          ;


   HelloWorldLayer.h

[cpp] view plaincopyprint?//   
//  HelloWorldLayer.h   
//  ScrollViewByHimi   
//   
//  Created by      on 11-10-22.   
//  Copyright __MyCompanyName__ 2011 . All rights reserved.   
//   
  
  
// When you import this file, you import all the cocos2d classes   
#import "cocos2d.h"   
#import "MyView.h"   
// HelloWorldLayer   
@interface HelloWorldLayer : CCLayer  
{  
    MyView *view;  
}  
  
// returns a CCScene that contains the HelloWorldLayer as the only child   
+(CCScene *) scene;  
  
@end  
//
//  HelloWorldLayer.h
//  ScrollViewByHimi
//
//  Created by      on 11-10-22.
//  Copyright __MyCompanyName__ 2011 . All rights reserved.
//


// When you import this file, you import all the cocos2d classes
#import "cocos2d.h"
#import "MyView.h"
// HelloWorldLayer
@interface HelloWorldLayer : CCLayer
{
    MyView *view;
}

// returns a CCScene that contains the HelloWorldLayer as the only child
+(CCScene *) scene;

@end

 

   HelloWorldLayer.m

 

[cpp] view plaincopyprint?//   
//  HelloWorldLayer.m   
//  ScrollViewByHimi   
//   
//  Created by      on 11-10-22.   
//  Copyright __MyCompanyName__ 2011 . All rights reserved.   
//   
  
  
// Import the interfaces   
#import "HelloWorldLayer.h"   
#import "MyView.h"   
// HelloWorldLayer implementation   
@implementation HelloWorldLayer  
  
+(CCScene *) scene  
{   
    CCScene *scene = [CCScene node];   
    HelloWorldLayer *layer = [HelloWorldLayer node];   
    [scene addChild: layer];   
    return scene;  
}  
   
-(id) init  
{   
    if( (self=[super init])) {  
          
        view= [[MyView alloc] initWithNibName:@"MyView" bundle:nil];    
        [[[CCDirector sharedDirector] openGLView] addSubview:view.view];    
        [self schedule:@selector(viewAddPointY) interval:0.03];// 0.03     viewAddPointY    
    }  
    return self;  
}  
-(void)viewAddPointY{  
    view.scrollView.contentOffset=ccpAdd(view.scrollView.contentOffset, ccp(0,0.5));// UIScrollView            0.5    
    //view.scrollView.contentSize.height :  UIScrollView      
    if(view.scrollView.contentOffset.y>=view.scrollView.contentSize.height){  
        view.scrollView.contentOffset=ccp(0,-view.scrollView.frame.size.height); 
    }  
}  
   
- (void) dealloc  
{    
    [super dealloc];  
}  
@end  
//
//  HelloWorldLayer.m
//  ScrollViewByHimi
//
//  Created by      on 11-10-22.
//  Copyright __MyCompanyName__ 2011 . All rights reserved.
//


// Import the interfaces
#import "HelloWorldLayer.h"
#import "MyView.h"
// HelloWorldLayer implementation
@implementation HelloWorldLayer

+(CCScene *) scene
{ 
 CCScene *scene = [CCScene node]; 
 HelloWorldLayer *layer = [HelloWorldLayer node]; 
 [scene addChild: layer]; 
 return scene;
}
 
-(id) init
{ 
 if( (self=[super init])) {
  
        view= [[MyView alloc] initWithNibName:@"MyView" bundle:nil];  
        [[[CCDirector sharedDirector] openGLView] addSubview:view.view];  
        [self schedule:@selector(viewAddPointY) interval:0.03];// 0.03     viewAddPointY  
 }
 return self;
}
-(void)viewAddPointY{
    view.scrollView.contentOffset=ccpAdd(view.scrollView.contentOffset, ccp(0,0.5));// UIScrollView            0.5  
    //view.scrollView.contentSize.height :  UIScrollView   
    if(view.scrollView.contentOffset.y>=view.scrollView.contentSize.height){
        view.scrollView.contentOffset=ccp(0,-view.scrollView.frame.size.height);
    }
}
 
- (void) dealloc
{  
 [super dealloc];
}
@end


        OK,    ;     ,                  ,                     ~        ~  ~


【2011 11 15   :】
   :         UIScrollView         :
       《      coco2d  scrollview         ,     UIScrollView        ,             ,    cocos2d      ,    FPS   ,  scrollview     ,             。。。                ?    ~》

      :
[html] view plaincopyprint?0.99.5   ..  
  
  : CCDirectorIOS.m      640        .  
  
//  
// If you want to attach the opengl view into UIScrollView  
// uncomment this line to prevent 'freezing'. It doesn't work on  
// with the Fast Director  
//  
// [[NSRunLoop currentRunLoop] addTimer:animationTimerforMode:NSRunLoopCommonModes];