参考書籍:
iPhone/iPad/iPod touch プログラミングバイブル iOS 6/Xcode 4対応 (smart phone programming bible)
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
CGRect targetRect = CGRectMake(0, 0, 44, 44);
CGPoint location = [[touches anyObject] locationInView:self];
if (CGRectContainsPoint(targetRect, location)) {
NSLog(@"touched in targetRect");
}
}
[[UIScreen mainScreen] bounds].size.width //幅 [[UIScreen mainScreen] bounds].size.height //高さ
[[UIScreen mainScreen] applicationFrame].size.width //幅 [[UIScreen mainScreen] applicationFrame].size.height //高さ
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//(A)ステータスバーを隠す
//[UIApplication sharedApplication].statusBarHidden = YES;
//(B)ステータスバーをランドスケープにする
//[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft];
//ステータスバーを含んだ画面サイズ
CGRect bounds = [[UIScreen mainScreen] bounds];
NSLog(@"bounds width:%.f height:%.f", bounds.size.width, bounds.size.height);
//ステータスバーを覗いた画面サイズ
CGRect aFrame = [[UIScreen mainScreen] applicationFrame];
NSLog(@"aFrame width:%.f height:%.f", aFrame.size.width, aFrame.size.height);
return YES;
}
bounds width:320 height:480 aFrame width:320 height:460
bounds width:320 height:480 aFrame width:320 height:480
bounds width:320 height:480 aFrame width:300 height:480
bounds width:320 height:480 aFrame width:320 height:480
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self != nil) {
self.multipleTouchEnabled = YES;
}
return self;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSInteger touchCount = [touches count];
NSLog(@"touchesBegan: count = %d", touchCount);
NSEnumerator *enumulator = [touches objectEnumerator];
UITouch *touchObject;
while (touchObject = [enumulator nextObject]) {
CGPoint tmpLocation = [touchObject locationInView:self];
NSLog(@"touchesBegan: (x, y) = (%.0f, %.0f)", tmpLocation.x, tmpLocation.y);
}
}
2012-07-30 00:39:44.320 HelloWorld[13321:f803] touchesBegan: count = 2 2012-07-30 00:39:44.324 HelloWorld[13321:f803] touchesBegan: (x, y) = (145, 155) 2012-07-30 00:39:44.325 HelloWorld[13321:f803] touchesBegan: (x, y) = (175, 325)
| LED 懐中電灯 HD(iPad) |