2010-12-20 2 views
13

아이폰 폴더 같은 모습으로 내보기를 변형 할 수있는 방법이 있는지 알고 싶습니다. 즉, 내 견해가 중간에 어딘가로 나뉘어 그 밑에있는 견해를 드러내 길 원합니다. 이것이 가능한가? iPhone Folders와 같은 것을 만드는 방법은 무엇입니까?

alt text

편집

: 아래의 제안 당 , 내가 이 일을함으로써 내 응용 프로그램의 스크린 샷을 걸릴 수 :

UIGraphicsBeginImageContext(self.view.bounds.size); 
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

그러나이 함께 할 무엇 확실하지. 편집

: 여기 내보기에 어떤 그림자를 추가하는 방법을 알아 냈어요 2 내가 달성 한 것입니다 (관련 부분 보여립니다) :

alt text

편집을 : 3

http://github.com/jwilling/JWFolders

+0

아, 잘 cocoacontrols.com에서 당신을 찾았습니다. 좋은 동료 ^^. 오픈 소스 FTW! =) –

+0

실제로 그렇게했습니다. 처음부터 저를 시작하도록 도와 주셔서 감사합니다. ;) –

+0

'OGActionChooser';에서 살펴볼 수 있습니다.)하지만 현재 서버 문제가있는 것 같습니다 : ( –

답변

6

기본적인 생각은 CUR의 사진을 촬영하는 것 임대 주와 그것을 어딘가에 나누십시오. 그런 다음 새 프레임을 설정하여 두 부분에 애니메이션을 적용합니다. 나는 ... 프로그래밍 그래서 샘플 코드를 제공 할 수없는 화면을 캡처하는 방법을

편집을 모르는 : 이봐 이봐 그것은 멋져 보이는 아니에요하지만 당신은 두 .contentMode 주석을 해제 할 수 있습니다 ^^

// wouldn't be sharp on retina displays, instead use "withOptions" and set scale to 0.0 
// UIGraphicsBeginImageContext(self.view.bounds.size); 
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, 0.0); 
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *f = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

CGRect fstRect = CGRectMake(0, 0, 320, 200); 
CGRect sndRect = CGRectMake(0, 200, 320, 260); // was 0,200,320,280 


CGImageRef fImageRef = CGImageCreateWithImageInRect([f CGImage], fstRect); 
UIImage *fCroppedImage = [UIImage imageWithCGImage:fImageRef]; 
CGImageRelease(fImageRef); 

CGImageRef sImageRef = CGImageCreateWithImageInRect([f CGImage], sndRect); 
UIImage *sCroppedImage = [UIImage imageWithCGImage:sImageRef]; 
CGImageRelease(sImageRef); 


UIImageView *first = [[UIImageView alloc]initWithFrame:fstRect]; 
first.image = fCroppedImage; 
//first.contentMode = UIViewContentModeTop; 
UIImageView *second = [[UIImageView alloc]initWithFrame:sndRect]; 
second.image = sCroppedImage; 
//second.contentMode = UIViewContentModeBottom; 

UIView *blank = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 460)]; 
blank.backgroundColor = [UIColor darkGrayColor]; 

[self.view addSubview:blank]; 
[self.view addSubview:first]; 
[self.view addSubview:second]; 

[UIView animateWithDuration:2.0 animations:^{ 
    second.center = CGPointMake(second.center.x, second.center.y+75); 
}]; 

를 작동 라인 및 품질 향상됩니다 내 경우에는 하위 뷰를 10px 정도의 오프셋이 있습니다 (두 subviews 배경색을 설정하여 볼 수 있습니다)

// EDIT 2 : 확인 해당 버그를 발견했습니다. 전체 320x480 화면을 사용했지만 상태 표시 줄을 잘라내어 320x460이어야하며 모두 잘 작동해야합니다.)

+0

그럴 수 있습니다 ... 나는 그것을 분할하는 방법을 모른다. –

+0

CoreGraphics 또는 Cocos2d가 작동해야한다고 생각합니다. UIImageView를 사용하는 경우 캡쳐 할 영역을 지정할 수있는 경우 스크린 샷을 찍는 것이 더 간단 할 수 있습니다. 자동 크기 조정을 설정하여 항상 위쪽/아래쪽 모서리에 머물도록 한 다음 프레임을 조금만 자르십시오. –

+0

감사합니다. –

2

보기의 스냅 샷을 찍는 대신 각 행에 대해 별도의보기를 사용할 수 있습니다. 아이콘. 재 위치 지정 작업을 통해 좀 더 많은 작업을해야하지만 폴더가 열려있을 때 행은 고정되지 않습니다. 즉, 필요에 따라 행이 다시 그려집니다.

+0

Dave, 의견을 보내 주셔서 감사합니다! 나는 실제로 아이콘을 원하지 않고 (내 대답에 명확히 했음),보기를 절반으로 분할하려고했습니다. –

1

relikd's 코드를 기본 코드로 사용하여 좀 더 동적으로 만들었습니다.

함수를 호출 할 때 분할 위치와 방향을 지정할 수 있으며 분할 된 이미지에 경계선을 추가했습니다.

#define splitAnimationTime 0.5 
- (void)split:(SplitDirection)splitDirection 
atYPostition:(int)splitYPosition 
withRevealedViewHeight:(int)revealedViewHeight{ 

    // wouldn't be sharp on retina displays, instead use "withOptions" and set scale to 0.0 
    // UIGraphicsBeginImageContext(self.view.bounds.size); 
    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, 0.0); 
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
    UIImage *f = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

    CGRect fullScreenRect = [self getScreenFrameForCurrentOrientation]; 

    CGRect upperSplitRect = CGRectMake(0, 0,fullScreenRect.size.width, splitYPosition); 
    CGRect lowerSplitRect = CGRectMake(0, splitYPosition, fullScreenRect.size.width, fullScreenRect.size.height-splitYPosition); 


    CGImageRef upperImageRef = CGImageCreateWithImageInRect([f CGImage], upperSplitRect); 
    UIImage *upperCroppedImage = [UIImage imageWithCGImage:upperImageRef]; 
    CGImageRelease(upperImageRef); 

    CGImageRef lowerImageRef = CGImageCreateWithImageInRect([f CGImage], lowerSplitRect); 
    UIImage *lowerCroppedImage = [UIImage imageWithCGImage:lowerImageRef]; 
    CGImageRelease(lowerImageRef); 


    UIImageView *upperImage = [[UIImageView alloc]initWithFrame:upperSplitRect]; 
    upperImage.image = upperCroppedImage; 
    //first.contentMode = UIViewContentModeTop; 

    UIView *upperBoarder = [[UIView alloc]initWithFrame:CGRectMake(0, splitYPosition, fullScreenRect.size.width, 1)]; 
    upperBoarder.backgroundColor = [UIColor whiteColor]; 
    [upperImage addSubview:upperBoarder]; 


    UIImageView *lowerImage = [[UIImageView alloc]initWithFrame:lowerSplitRect]; 
    lowerImage.image = lowerCroppedImage; 
    //second.contentMode = UIViewContentModeBottom; 

    UIView *lowerBoarder = [[UIView alloc]initWithFrame:CGRectMake(0, 0, fullScreenRect.size.width, 1)]; 
    lowerBoarder.backgroundColor = [UIColor whiteColor]; 
    [lowerImage addSubview:lowerBoarder]; 

    int reveledViewYPosition = splitYPosition; 

    if(splitDirection==SplitDirectionUp){ 
     reveledViewYPosition = splitYPosition - revealedViewHeight; 
    } 


    UIView *revealedView = [[UIView alloc]initWithFrame:CGRectMake(0, reveledViewYPosition, fullScreenRect.size.width, revealedViewHeight)]; 
    revealedView.backgroundColor = [UIColor scrollViewTexturedBackgroundColor]; 


    [self.view addSubview:revealedView]; 
    [self.view addSubview:upperImage]; 
    [self.view addSubview:lowerImage]; 

    [UIView animateWithDuration:splitAnimationTime animations:^{ 
     if(splitDirection==SplitDirectionUp){ 
      upperImage.center = CGPointMake(upperImage.center.x, upperImage.center.y-revealedViewHeight); 
     } else { //assume down 
      lowerImage.center = CGPointMake(lowerImage.center.x, lowerImage.center.y+revealedViewHeight); 
     } 
    }]; 
} 

이것은 내가 이런 식으로 호출 할 수 있습니다 의미 :

[self split:SplitDirectionUp atYPostition:500 withRevealedViewHeight:200]; 
내가 업데이트 된 분할 기능에서 이러한 conveniance 기능을 사용

:

- (CGRect)getScreenFrameForCurrentOrientation { 
    return [self getScreenFrameForOrientation:[UIApplication sharedApplication].statusBarOrientation]; 
} 

- (CGRect)getScreenFrameForOrientation:(UIInterfaceOrientation)orientation { 

    UIScreen *screen = [UIScreen mainScreen]; 
    CGRect fullScreenRect = screen.bounds; 
    BOOL statusBarHidden = [UIApplication sharedApplication].statusBarHidden; 

    //implicitly in Portrait orientation. 
    if(orientation == UIInterfaceOrientationLandscapeRight || orientation == UIInterfaceOrientationLandscapeLeft){ 
     CGRect temp = CGRectZero; 
     temp.size.width = fullScreenRect.size.height; 
     temp.size.height = fullScreenRect.size.width; 
     fullScreenRect = temp; 
    } 

    if(!statusBarHidden){ 
     CGFloat statusBarHeight = 20; 
     fullScreenRect.size.height -= statusBarHeight; 
    } 

    return fullScreenRect; 
} 

이 열거 :

typedef enum SplitDirection 
{ 
    SplitDirectionDown, 
    SplitDirectionUp 
}SplitDirection; 

normaal f에 복귀 추가 통치와 화살 추가는 큰 도움이 될 것입니다.

+1

오래전에 내가 쓴 라이브러리를 보면서이 모든 내용을 살펴볼 수 있습니다. https://github.com/jwilling/JWFolders –

+0

하, 고마워. 이것이 이것을 시작하기 전에 이것이 여기에 있었으면 좋겠다! –

+0

ㅎ 그래, 미안, 내가 게시 했어야했다. 자, 위안을 위로로 가져라. :) –

관련 문제