iOS Development

图片从中间分开效果

2016-05-19  本文已影响72人  71150ce14a00

UIImageView*img1;

UIImageView*img2;

img1= [[UIImageViewalloc]initWithFrame:CGRectMake(0,0,ScreenWidth,ScreenHeight*0.5)];

img2= [[UIImageViewalloc]initWithFrame:CGRectMake(0,ScreenHeight*0.5,ScreenWidth,ScreenHeight*0.5)];

UIImage*img = [UIImageimageNamed:@"333.jpg"];

CGImageRefrefImage =CGImageCreateWithImageInRect(img.CGImage,CGRectMake(0,0,ScreenWidth,ScreenHeight*0.5));

UIImage*image1 = [UIImageimageWithCGImage:refImage];

img1.image= image1;

[self.viewaddSubview:img1];

CGImageRefrefImage2 =CGImageCreateWithImageInRect(img.CGImage,CGRectMake(0,ScreenHeight*0.5,ScreenWidth,ScreenHeight*0.5));

UIImage*image2 = [UIImageimageWithCGImage:refImage2];

img2.image= image2;

[self.viewaddSubview:img2];

button= [[UIButtonalloc]initWithFrame:CGRectMake(100,100,30,30)];

button.backgroundColor= [UIColorredColor];

[buttonaddTarget:selfaction:@selector(buttonAction)forControlEvents:UIControlEventTouchUpInside];

[self.viewaddSubview:button];

触发事件:

打开

[UIViewanimateWithDuration:1animations:^{

img1.frame=CGRectMake(0, -ScreenHeight*0.5,ScreenWidth,ScreenHeight*0.5);

img2.frame=CGRectMake(0,ScreenHeight,ScreenWidth,ScreenHeight*0.5);

}];

合并

[UIViewanimateWithDuration:1animations:^{

_myImage.frame=CGRectMake(0,0,WIDTH,HEIGHT*0.5);

_myImage1.frame=CGRectMake(0,HEIGHT*0.5,WIDTH,HEIGHT*0.5);

}]

上一篇下一篇

猜你喜欢

热点阅读