iOS2012. 9. 18. 00:37

//경고창 1.

UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"A" message:@"" delegate:self cancelButtonTitle:@"확인" otherButtonTitles:@"취소"nil];

[alert show];

[alert release];


//경고창 2

UIAlertView *alert =[[UIAlertView alloc]initWithTitle:@"B" message:@"" delegate:self 

cancelButtonTitle:@"확인" otherButtonTitles:@"취소"nil];

[alert show];

[alert release];


//경고창 3

UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"C" message:@"" delegate:self 

cancelButtonTitle:@"확인" otherButtonTitles:@"취소"nil];

[alert show];

[alert release];



//경고창의 버튼 이벤트를 감지하는 델리게이트.

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex

{

//경고창의 타이틀을 비교해서 경고창을 구별한다.

if ( [[alertView titleisEqualToString:@"A"])

{

        if(buttonIndex==0){

}else {

}

    

}

else if ( [[alertView titleisEqualToString:@"B"]) 

{

if(buttonIndex==0){

}

}

else if ( [[alertView titleisEqualToString:@"C"]) 

{

if(buttonIndex==0){

}

}

}

Posted by 다오나무
iOS2012. 9. 18. 00:24

http://www.iphonedevsdk.com/forum/iphone-sdk-development/61426-multiple-action-sheets-problem.html
UIActionSheet *actionSheet1;
UIActionSheet *actionSheet2;
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if(actionSheet==actionSheet1)
{
do this}
else
if(actionSheet==actionSheet2)
{do that}
}

Posted by 다오나무
iOS2012. 9. 17. 22:07

addSubView 된 객체에 대한 접근 방법


서브뷰 내에 어떻게 뷰들이 분포해 있는지 알 수 없기 때문에

아래와 같은 식으로 태그값을 이용해서 조작을 원하는 뷰를 찾은 다음에 그 뷰를 조작해야 합니다.

 

for(UIView *v in [scrollView.SubScrollView subviews]) {

if(v.tag == index) v.frame = rect;

}


Posted by 다오나무
iOS2012. 9. 17. 18:21

간단한 뷰를 만들었는데요.. 화면 밑에 이미지나 버튼을 넣었을때 핫스팟이나 인터넷 테더링이 활성화 되어서 상태바가 두줄이 생겼을 경우엔 화면이 잘립니다. 

상태바가 두줄이 되었을경우의 조건을 주어 좌표 수정을 하고 싶은데 조건 문의 드립니다. 

감사합니다. 
  • 2011/09/20 10:35답글

    신고

    앵커로 처리하시면 될 듯..;;

  • 2011/09/20 19:02답글

    신고

    Uiapplication 의 shared인스턴스를 따와서 델리게이트를 설정해주신후에 거기에 delegate method 중에 statusbarframe change 같은 델리게이트 메소드가있습니다 그거활용하심될듯요

Posted by 다오나무
iOS2012. 9. 17. 13:14

This is the approach I use for iOS 4 and 5 compatibility:

if ([toolbar respondsToSelector:@selector(setBackgroundImage:forToolbarPosition:barMetrics:)]) {
   
[toolbar setBackgroundImage:[UIImage imageNamed:@"toolbar-background"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
} else {
   
[toolbar insertSubview:[[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"toolbar-background"]] autorelease] atIndex:0];
}

Posted by 다오나무
iOS2012. 9. 13. 23:49

I just want to enable/disable the status bar per view controller (some view full screen, some not)

I've been several times through all the post related to the status bar 20 pixels issue, but still have the problem, especially on iOS5.0 (some trick worked on older iOS version):

Here is the problem definition:

  • I use [[UIApplication sharedApplication] setStatusBarHidden:YES] to hide the status bar

  • I always have the 20 pixel height white empty area if I do this

  • I've try to enable/disable the navigation bar to force a layout, this does not works on iOS 5:

    [self.navigationController setNavigationBarHidden:NO animated:NO];
    [self.navigationController setNavigationBarHidden:YES animated:NO];
  • I've try to manually reset the view frame size, no change

    self.view.frame=CGRectMake(0, 0, 320, 480);

  • I've tried to change manually the navigation container view:

    self.navigationController.frame=CGRectMake(0, 0, 320, 480);

  • All the view are of course 480 pixels height

share|improve this question

62% accept rate
First try to improve your accept rate it's too low – Wolvorin Jul 27 at 13:27
so you have a tip @AalokParikh ? – tomsoft Aug 8 at 17:59
I use this to show and hide the statusbar [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone]; And also design view according to the statusbar's hidden status ie. If statusbar is hidden I design my View with no statusbar in it. :) – Wolvorin Aug 9 at 9:37
well, I've tried this too , but the beahvior also is different depending of the iOS version. I've finally had to rewrite completely the navigation framework in order to be 100% sur to manage it... – tomsoft Aug 9 at 11:59
Oh I dont get any difference or not been able to detect it sorry :( – Wolvorin Aug 9 at 12:00
show 2 more comments
Was this post useful to you?     

Use the following method in viewWillAppear of view controller to which you would like to display StatusBar.

[[UIApplication sharedApplication]setStatusBarHidden:YES];

Declare one BOOL variable to indicate whether status bar is hidden or not while view is loaded in view controller which you would like to hide status bar and set its value to NO.

BOOL statusBarHidden = NO;

Then add the following code in viewWillAppear of view controller(Status Bar is hidden in this view)

[[UIApplication sharedApplication] setStatusBarHidden:YES];
if(statusBarHidden == NO)
{
   
self.navigationController.navigationBar.frame = CGRectOffset(self.navigationController.navigationBar.frame, 0.0, -20.0);
    statusBarHidden
= YES;

}

Posted by 다오나무
iOS2012. 9. 13. 23:17

게임을 만들때 반드시 처리해야 할일 상태바를 감춰야 한다.

게임에서는 상태바에 시간 베터리 양이 보이면 상대적으로 몰입도가 떨어진다.

아무리 보드게임이라 할지라도 반드시 없애 줘야 사용자가 좀더 게임에 몰입한다.

이게 근데 어떻게 설정 해서 하는건지 모르면 난감하다.


AppDelegate 소스에

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Hide the status bar
    [UIApplicationsharedApplication].statusBarHidden = YES;

위와 같은 간단한 코드로 해결이 된다.

오늘의 팁은 끝!

Posted by 다오나무
iOS2012. 9. 13. 13:49

UIImageView를 터치했을 경우의 이벤트를 얻어야 할 경우.
UIControl을 이용해 이벤트를 얻어온다.

1. UIImageView 생성.
2. UIControl 타입의 mask 생성.
3. mask 에 imageView 자식 뷰로 추가
4. mask 에 이벤트 설정.
5. 현재의 뷰컨트롤러의 뷰에 자식뷰로 mask 추가.



    UIImage * image = [UIImage imageNamed:@"sexy.jpg"];

    UIImageView * imageView = [[[UIImageView allocinitWithImage:image] autorelease];

    [imageView setFrame:CGRectMake(10.0f10.0f90.0f90.0f)];

    [imageView.layer setBorderColor:[[UIColor grayColorCGColor]];

    [imageView.layer setBorderWidth:1.0];

    [imageView.layer setCornerRadius:10.0];

    [imageView.layer setMasksToBounds:YES];

    

    UIControl * mask = [[[UIControl allocinitWithFrame:imageView.frameautorelease];

    

    CGSize imageSize = imageView.frame.size;

    imageView.frame = CGRectMake(00, imageSize.width, imageSize.height);

    [mask addSubview:imageView];

    

    [mask addTarget:self action:@selector(cancelButtonPush:) forControlEvents:UIControlEventTouchUpInside];

    

    [self.view addSubview:mask];

Posted by 다오나무
iOS2012. 9. 13. 13:34


왼쪽의 그림은 서클(또는 휠) 메뉴이다. 적당한 이름이 생각나지 않아 그냥 서클 메뉴라 칭했다. 좌우 제스처(gesture)를 이용해 메뉴를 좌우로 이동 시킨다. 그리고 메뉴가 보이는 상테에서 상하 제스처를 이용해 서클 메뉴를 이동 시킨다. 

샘플로 첨부한 프로젝트는 이러한 애니메이션을 구현한 예이다. 실제 사용하기 위해서는 메뉴에 실제 버튼(예에서는 단순히 배경이미지만을 보여 준다.)을 추가해 이때 처리할 로직을 추가해야 한다.

원형의 메뉴를 위한 애니메이션을 위해 CGAffineTransformMakeRotation를 사용해 좌표 시스템을 이동시키는 방법을 사용했다. 그런데 이때 상하 제스처를 쉽게 사용하기 위해 CircleMenu라는 백그라운드 역할을 뷰위에 원형의 메뉴 이미지를 올려 놓았다. 이렇게 하지 않으면 좌표 시스템의 이동에 따라 상하 제스처를 제대로 이용할 수 없다.

간단히 코드를 살표 보자. 자세한 내용은 다음에 첨부한 샘플 프로젝트를 참고하라.


우선 Xcode에서 View-based Application 템플릿을 이용해 프로젝트를 생성하자. 그리고 서클 메뉴의 백그라운드로 이용할 CircleMenu 클래스를 생성한다. 실제 사용하기 위해서는 이 곳에 버튼과 관련된 내용을 추가해야 한다. 샘플에서는 제스처 이벤트만을 처리하고 있다.

그리고 CircleMenuViewController를 다음과 같이 수정한다.

[CircleMenuViewController.h]

#import <UIKit/UIKit.h>

#import <QuartzCore/QuartzCore.h>
#import <AVFoundation/AVFoundation.h> 

#import <Audiotoolbox/AudioToolbox.h>


@class CircleMenu;


@interface CircleMenuViewController : UIViewController {

    UIButton *toggleButton; // 화살표 버튼.

    float lastRadian;

    BOOL isLeft; // 화살표 이미지 상태.

}


@property (nonatomicretainCircleMenu *circle;

@property (nonatomicretainUIImageView *imageView;

@property (nonatomicretainIBOutlet UIButton *toggleButton;


- (void)rotateCircleMenu:(UISwipeGestureRecognizer *)recognizer;

- (void)moveToLeftOrRight:(UISwipeGestureRecognizer *)recognizer;

- (void)playSound;


@end


[CircleMenuViewController.m]

#import "CircleMenuViewController.h"

#import "CircleMenu.h"


#define degreesToRadian(x) (M_PI * (x) / 180.0)



@implementation CircleMenuViewController


@synthesize circle;

@synthesize imageView;

@synthesize toggleButton;


- (void)dealloc

{

    [circle release];

    [imageView release];

    [toggleButton release];

    [super dealloc];

}

// 생략...
 

- (void)viewDidLoad

{

    [super viewDidLoad];

    

    isLeft = YES;

    

    self.circle = [[CircleMenu allocinitWithFrame:CGRectMake(0.00.0225.0225.0)];

    self.circle.center = CGPointMake(420240);

    [self.view addSubview:circle];

    

    UIImage *image = [UIImage imageNamed:@"circle.png"];

    imageView = [[UIImageView allocinitWithImage:image];

    self.imageView.bounds = self.circle.frame;

    [self.circle addSubview:imageView];

    

    lastRadian = 0.0;

    

    // UISwipeGestureRecognizer 인스턴스 생성.

UISwipeGestureRecognizer *recognizerUp = [[[UISwipeGestureRecognizer allocinitWithTarget:selfaction:@selector(rotateCircleMenu:)] autorelease];

// 스와이프 제스처를 인식하기위한  .

recognizerUp.numberOfTouchesRequired = 1;

// 스와이프의 방향.

    recognizerUp.direction = UISwipeGestureRecognizerDirectionUp;

[self.circle addGestureRecognizer:recognizerUp];

UISwipeGestureRecognizer *recognizerDown = [[[UISwipeGestureRecognizer allocinitWithTarget:selfaction:@selector(rotateCircleMenu:)] autorelease];

// 스와이프 제스처를 인식하기위한  .

recognizerDown.numberOfTouchesRequired = 1;

// 스와이프의 방향.

    recognizerDown.direction = UISwipeGestureRecognizerDirectionDown;

[self.circle addGestureRecognizer:recognizerDown];

    

    UISwipeGestureRecognizer *recognizerLeft = [[[UISwipeGestureRecognizer allocinitWithTarget:selfaction:@selector(moveToLeftOrRight:)] autorelease];

// 스와이프 제스처를 인식하기위한  .

recognizerLeft.numberOfTouchesRequired = 1;

// 스와이프의 방향.

    recognizerLeft.direction = UISwipeGestureRecognizerDirectionLeft;

[self.view addGestureRecognizer:recognizerLeft];

// UISwipeGestureRecognizer 인스턴스 생성.

UISwipeGestureRecognizer *recognizerRight = [[[UISwipeGestureRecognizer allocinitWithTarget:selfaction:@selector(moveToLeftOrRight:)] autorelease];

// 스와이프 제스처를 인식하기위한  .

recognizerRight.numberOfTouchesRequired = 1;

// 스와이프의 방향.

    recognizerRight.direction = UISwipeGestureRecognizerDirectionRight;

[self.view addGestureRecognizer:recognizerRight];

    



// 생략...

#pragma mark - 커스텀 메서드


// 메뉴 회전.

- (void)rotateCircleMenu:(UISwipeGestureRecognizer *)recognizer

{   

    NSLog(@"Before frame: %@"NSStringFromCGRect(self.circle.frame));

    if (recognizer.direction == UISwipeGestureRecognizerDirectionUp) {

        lastRadian += 26;

}

if (recognizer.direction == UISwipeGestureRecognizerDirectionDown) {

        lastRadian -= 26;

}

    

    [UIView beginAnimations:@"Rotation" context:nil];

    [UIView setAnimationDuration:0.7];

    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

    

    self.imageView.transform = CGAffineTransformMakeRotation(degreesToRadian(lastRadian));

    [self playSound];

    

    [UIView commitAnimations];

    

    NSLog(@"Last radian: %f"lastRadian);

    NSLog(@"After frame: %@"NSStringFromCGRect(self.circle.frame));

}


// 메뉴 이동(/).

- (void)moveToLeftOrRight:(UISwipeGestureRecognizer *)recognizer

{

    UIImage *image;

float moveCenterX;

if (isLeft && recognizer.direction == UISwipeGestureRecognizerDirectionLeft) {

moveCenterX = -100.0;

image = [UIImage imageNamed:@"icon_right.png"];

isLeft = NO;

}

if (!isLeft && recognizer.direction == UISwipeGestureRecognizerDirectionRight) {

moveCenterX = 100.0;

image = [UIImage imageNamed:@"icon_left.png"];

isLeft = YES;

}

    

    // iOS4+: Blocks 사용.

    [UIView animateWithDuration:0.7

  delay:0.1

options:UIViewAnimationCurveEaseOut

 animations:^{

 self.circle.center = CGPointMake(self.circle.center.x + moveCenterX, 240);

                         self.toggleButton.center = CGPointMake(self.toggleButton.center.x + moveCenterX,self.toggleButton.center.y);

 [self.toggleButton setImage:imageforState:UIControlStateNormal];

 } 

 completion:^(BOOL finished){

 NSLog(@"Done!");

 }];

}


// 사운드 효과.

- (void)playSound

{

    NSString *path = [[NSBundle mainBundlepathForResource:@"sound" ofType:@"mp3"];

NSURL *url = [NSURL fileURLWithPath:path];

AVAudioPlayer *player = [[AVAudioPlayer allocinitWithContentsOfURL:url error:nil];

//[player setNumberOfLoops:1];

    //[player playAtTime:1.5];

    [player play];

}


@end 


 버튼을 추가하는 방법은 여러 가지가 있겠으나, 좀더 효과적인 것이 무엇일까 고민 중이다. 좋의 의견 있는 분들은 댓글을 남겨 주십시오!

Posted by 다오나무
iOS2012. 9. 13. 13:17

UIViewController 를 이용한 메인뷰 또는 특정뷰에서 일련의 백그라운드 작업시 대기상태를 나타내주는 여러 방법(Modal Popup, Spinner, SubView 등...)들 중에, 카테고리를 이용하여 간단한 Method 호출로 UIViewController 에 오버레이되는 View 를 생성해 보자.


CREATE CATEGORY 


UIViewControll+OverlayView.h

1
2
3
4
5
6
7
#import <UIKit/UIKit.h>
 
@interface UIViewController (OverlayView)
 
-(void)showLayer:(NSString *)message;
-(void)hideLayer;
@end

UIViewController+OverlayView.m

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#import "UIViewController+OverlayView.h"
 
@implementation UIViewController (OverlayView)
 
-(void)showLayer:(NSString *)message
{
    UIView *layer = [[UIView alloc] initWithFrame:self.view.bounds];
    // layer.alpha = 0.5;
    layer.backgroundColor = [[UIColor clearColor] colorWithAlphaComponent:0.5];
     
    /* Create Label */
    UILabel *label = [[UILabel alloc] initWithFrame:self.view.bounds];
    label.textAlignment = UITextAlignmentCenter;
    label.lineBreakMode = YES; // 개행 설정.
    label.numberOfLines = 0; // 개행 숫자에 제한을 두지 않음.
    label.backgroundColor = [UIColor clearColor];
    label.textColor = [UIColor whiteColor];
    label.text = message;
    [layer addSubview:label];
    [label release];
     
    /* Add LayerView */
    [self.view addSubview:layer];
    [layer release];
}
 
-(void)hideLayer
{
    NSArray *subViews = [self.view subviews];
    UIView *layer = [subViews lastObject];
    [layer removeFromSuperview];
}
@end

※ alpha 를 적용하게되면, UIView *layer 에 올라오는 컨트롤 및 서브뷰들도 해당 alpha value 가 적용되어 보여진다. 반면, backgroundColor 는 해당 View 에만 alpha value 가 적용된다.


USING CATEGORY


ViewController.m

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#import "ViewController.h"
#import "UIViewController+OverlayView.h"
 
@implementation ViewController
- (IBAction)onBtnAction:(id)sender {
    [self showLayer:@"MESSAGE TO SHOW"];
     
    [self performSelector:@selector(onHideLayer) withObject:nil afterDelay:2.0f];
}
 
- (void)onHideLayer
{
    [self hideLayer];
}
@end

테스트를 위해, 생성된 오버레이뷰를 performSelector 로 2초후 해제되게 작성. UIViewController 를 서브클래싱하는 클래스들에서 해당 카테고리를 임포트하여, 간단히 카테고리 메소드 호출.


RESULT


스크린샷 처럼, Spinner (UIActivityIndicatorView) 를 표시하거나 기타 다른 컨트롤뷰도 해당 오버레이뷰에 추가하여 프로젝트 성격에 맞게끔 커스터마이징.

1
2
3
4
5
6
7
8
9
/* Create Spinner */
    UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    spinner.center = CGPointMake(160, 200);
    spinner.hidesWhenStopped = NO;
    spinner.tag = 100;
    [layer addSubview:spinner];
     
    [spinner startAnimating];
    [spinner release];

Posted by 다오나무