2010-12-20 55 views
13

我想知道是否有方法可以将我的视图转换为iPhone文件夹。换句话说,我希望我的视角在中间的某个位置分开,并在其下方显示一个视图。这可能吗?如何制作类似iPhone文件夹的东西?

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

ahhh好,我在cocoacontrols.com上找到了你我的好人^^。开源FTW! =) – 2013-02-03 19:58:27

+0

的确如此。感谢您帮助我从头开始。 ;) – 2013-02-03 19:59:37

+0

你可以看看'OGActionChooser';)但是它似乎目前有服务器问题:( – 2013-02-03 20:03:40

回答

6

的基本思想将是把你的小人的图片租用国家并将其分开。然后通过设置一个新的框架为两个部分设置动画。我不知道如何采取截图编程,所以我不能提供的示例代码...

编辑:嘿它不看大,但它的工作原理^^

// 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); 
}]; 

您可以取消这两个.contentMode线条和质量会提高,但在我的情况下,子视图的偏移量为10px左右(可以通过为两个子视图设置背景颜色来看到它)

//编辑2:ok找到该错误。已经使用了整个320x480的屏幕,但不得不切断状态栏,所以它应该是320x460,并且所有的都很好;)

+0

这可能工作......我只是不知道如何分割它 – 2010-12-20 21:16:53

+0

我认为CoreGraphics或Cocos2d应该工作但如果您可以指定要捕捉的区域,或者如果您将使用UIImageView,则可以更简单地进行截图,您可以将自动调整大小设置为始终保持在顶部/底部角落,然后稍微切掉一帧 – 2010-12-20 21:19:50

+0

谢谢对于你的辛勤工作,它看起来不错,在做完这个之后我该如何回到主视图? – 2010-12-20 22:23:43

2

而不是拍摄视图的快照,您可以使用单独的视图为图标。你需要做更多的工作来重新定位东西,但是当文件夹打开时这些行不会是静态的(换句话说,它们会根据需要继续重绘)。

+0

Dave,感谢您的评论!我其实并不想要这些图标(应该在我的回答中予以澄清),但我只是想将视图分解成一半。 – 2010-12-21 16:55:59

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]; 

我在更新后的分割功能使用这些为了方便地使用功能:

- (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; 

将回归添加到常规f联合和增加箭头将是一个很好的补充。

+1

你可能有兴趣看到我刚才写的一个图书馆,它包装了所有这些。 https://github.com/jwilling/JWFolders – 2013-01-27 18:52:34

+0

哈,谢谢。希望这是在我开始之前在这里! – 2013-01-28 00:15:15

+0

嘿耶,对不起,我应该发布它。在这里,有一个安慰。 :) – 2013-01-28 00:47:57

相关问题