2011-11-18 5 views
3

iPad를 가로로 돌릴 때마다 배경과 프레임에 문제가 있습니다.목표 C : 방향 변경시 배경 및 프레임 문제

세로 :

enter image description here

풍경 : 나는 노란색 화살표 후 그 옆에 페인트 할 수없고 내 배경 세로 자체를 반복에 아직도있다.

enter image description here

여기있는 viewDidLoad에 내 코드

입니다 :있는 touchesMoved에

background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"mickey.png"]]; 
    self.view.backgroundColor = background; 

    touchDraw = [[UIImageView alloc] initWithImage:nil]; 
    touchDraw.frame = self.view.frame; 
    [self.view addSubview:touchDraw]; 
    [self.view sendSubviewToBack:touchDraw]; 
    touchMoved = 0; 

:

touchSwiped = YES; 
    UITouch *touch = [touches anyObject]; 
    currentTouch = [touch locationInView:self.view]; 
    currentTouch.y -= 20; 
    UIGraphicsBeginImageContext(self.view.frame.size); 
    [touchDraw.image drawInRect:CGRectMake(0, 0, touchDraw.bounds.size.width, touchDraw.bounds.size.height)]; 
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); 
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 25.0); 
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), redAmt, greenAmt, blueAmt, alpha); 
    CGContextBeginPath(UIGraphicsGetCurrentContext()); 
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), endingPoint.x, endingPoint.y); 
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentTouch.x, currentTouch.y); 
    CGContextStrokePath(UIGraphicsGetCurrentContext()); 
    touchDraw.image = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

    endingPoint = currentTouch; 

    touchMoved++; 

    if (touchMoved == 10) { 
     touchMoved = 0; 
    } 

그것은 내 학교 프로젝트입니다.

UPDATE :이있는 touchesMoved에 일어나는 autoResizingMask을 적용

. 어쩌면 때문에이 라인의

enter image description here

는 :

[touchDraw.image drawInRect:CGRectMake(0, 0, touchDraw.bounds.size.width, touchDraw.bounds.size.height)]; 

나는 여전히 같은 그 전에 해결하려고 노력하지만.

+1

질문에 대한 업데이트가 잘 이해가되지 않습니다. 무엇이 그림이고, 무엇을 기대 했습니까? 내가 생각할 수있는 몇 가지 제안은 1) 부모보기에 auutoresizingMask를 추가하고 자신의 touchesMoved 루틴에서보기에 대해 일관성을 유지하는지 확인해야합니다. 부모보기와 터치보기간에 전환합니다. 그들은 같은 크기 여야하지만, 그렇지 않다면 일관성 문제가있을 수 있습니다. – Ron

답변

1

코드를 빠르게 읽는 것으로, 잘못된 것이 무엇인지 추측 할 수 있습니다.

기본보기가 장치를 회전 할 때 다시 그려지는 방향 변경에 응답하고 있습니다. 당신은 패턴을 그렸고 패턴은 반복됩니다. 반복하지 않는 배경을 가지고 싶다면 UIImageView를 만들고 이미지를 "mickey.png"로 설정해야합니다.

생성 한 (touchDraw) 뷰에는 프레임이 주어집니다. 만들어졌으며 iPad를 돌릴 때 동적으로 업데이트되지 않습니다. 이 방향이 변경 될 때 자동 조정해야한다는 견해를 알려줍니다

touchDraw.autoresizingMask = UIViewAutoresizingFlexibleHeight 
    | UIViewAutoresizingFlexibleWidth; 

:

나는 당신이 필요합니다 모든라고 생각합니다.

당신은 또한 당신의 뷰 컨트롤러에이 방법을 추가해야 할 수도 있습니다 (I은 기본이입니다 잊지) :

- (BOOL)shouldAutorotateToInterfaceOrientation: 
    (UIInterfaceOrientation)interfaceOrientation { 
    return YES; 
} 

당신은 방향 변경을보다 세밀하게 제어 할 수 있습니다 이러한 두 가지 방법을 추가하여 보기 컨트롤러 :

- (void)willRotateToInterfaceOrientation: (UIInterfaceOrientation) orient 
           duration: (NSTimeInterval) duration 

- (void) didRotateFromInterfaceOrientation: 
    (UIInterfaceOrientation) orientation { 

주는 것을 경계가없는 곳에보기가 힘들다.내가 주변에 놀고있을 때

#import <QuartzCore/QuartzCore.h> 

: 당신이 # import를 포함해야합니다,

touchDraw.layer.borderWidth = 1; 
    touchDraw.layer.borderColor = [[UIColor blackColor] CGColor]; 

내가 위의 레이어 속성에 액세스 할 생각 : 디버깅, 당신은 사용하여 테두리를 설정할 수 있습니다 내 견해가있는 위치를 명확하게 볼 수 있도록 내 견해를 표시하는 위치, 종종 국경을 추가합니다.

"인터페이스 빌더"에는 자동 회전을 설정하는 설정이 있지만 C 코드로보기를 작성 중이므로 설정되어 있지 않습니다.

+0

감사합니다 선생님! 가로 방향으로 화면을 터치하기 시작하면 작동하지만 뭔가 잘못되었습니다. // 내가 편집 한 위의 게시물을 참조하십시오. – SeongHo