如何在iphone中实现图片的放大(不使用多点触控:即两个手指拉开) 现在想在iphone中实现iphone的图片放大功能,将一张小图片放大到手机全屏这样一个动画效果,我想用calayer来实现,可是对它不太熟,请熟悉的朋友帮帮忙。很急。多谢了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 请参照代码#import <UIKit/UIKit.h>#define IMAGE_VIEW_1 100#define IMAGE_VIEW_2 101#define BIGRECT CGRectMake(0.0f, 0.0f, 320.0f, 435.0f)#define SMALLRECT CGRectMake(130.0f, 187.0f, 60.0f, 60.0f) @interface ToggleView: UIView{ BOOL isOne;}@end@implementation ToggleView- (id) initWithFrame: (CGRect) aFrame;{ self = [super initWithFrame:aFrame]; // Load both views, make them non-interactive UIImageView *imgView1 = [[UIImageView alloc] initWithFrame:BIGRECT]; imgView1.image = [UIImage imageNamed:@"one.png"]; imgView1.userInteractionEnabled = NO; imgView1.tag = IMAGE_VIEW_1; UIImageView *imgView2 = [[UIImageView alloc] initWithFrame:SMALLRECT]; imgView2.image = [UIImage imageNamed:@"two.png"]; imgView2.userInteractionEnabled = NO; imgView2.tag = IMAGE_VIEW_2; // image 1 is in front of image 2 to begin [self addSubview:imgView2]; [self addSubview:imgView1]; isOne = YES; [imgView1 release]; [imgView2 release]; return self;}- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event{ // Determine which view occupies which role UIImageView *big = (UIImageView *)[self viewWithTag: (isOne ? IMAGE_VIEW_1 : IMAGE_VIEW_2)]; UIImageView *little = (UIImageView *)[self viewWithTag: (isOne ? IMAGE_VIEW_2 : IMAGE_VIEW_1)]; isOne = !isOne; // Pack all the changes into the animation block CGContextRef context = UIGraphicsGetCurrentContext(); [UIView beginAnimations:nil context:context]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; [UIView setAnimationDuration:1.0]; [big setFrame:SMALLRECT]; [big setAlpha:0.5]; [little setFrame:BIGRECT]; [little setAlpha:1.0]; [UIView commitAnimations]; // Hide the shrunken "big" image. [big setAlpha:0.0f]; [[big superview] bringSubviewToFront:big];}@end@interface HelloController : UIViewController@end@implementation HelloController- (void)loadView{ ToggleView *contentView = [[ToggleView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; contentView.backgroundColor = [UIColor whiteColor]; self.view = contentView; [contentView release];}@end@interface SampleAppDelegate : NSObject <UIApplicationDelegate> @end@implementation SampleAppDelegate- (void)applicationDidFinishLaunching:(UIApplication *)application { UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; HelloController *hello = [[HelloController alloc] init]; [window addSubview:hello.view]; [window makeKeyAndVisible];}@endint main(int argc, char *argv[]){ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, nil, @"SampleAppDelegate"); [pool release]; return retVal;} http://blog.csdn.net/cloudhsu/archive/2010/08/26/5841089.aspx该范例相关资料可到我的博客参考 iPhone控制其他设备 Mac Xcode4 如何把静态库.a加到工程,并调用静态库中的函数 使用mailcore无法获取126邮箱的邮件列表 Objact C语言? UITextView 只输入一行 ios通讯录排序 为什么我的tableview总爱缩成一个点 求推荐多因子认证,二次认证? 请问学习ios编程哪本书入门好一些 类似淘宝这种有背景色位置的字体颜色改变 关于XCode的使用 Iphone通讯录的问题
#define IMAGE_VIEW_2 101#define BIGRECT CGRectMake(0.0f, 0.0f, 320.0f, 435.0f)
#define SMALLRECT CGRectMake(130.0f, 187.0f, 60.0f, 60.0f) @interface ToggleView: UIView
{
BOOL isOne;
}
@end@implementation ToggleView- (id) initWithFrame: (CGRect) aFrame;
{
self = [super initWithFrame:aFrame];
// Load both views, make them non-interactive
UIImageView *imgView1 = [[UIImageView alloc] initWithFrame:BIGRECT];
imgView1.image = [UIImage imageNamed:@"one.png"];
imgView1.userInteractionEnabled = NO;
imgView1.tag = IMAGE_VIEW_1; UIImageView *imgView2 = [[UIImageView alloc] initWithFrame:SMALLRECT];
imgView2.image = [UIImage imageNamed:@"two.png"];
imgView2.userInteractionEnabled = NO;
imgView2.tag = IMAGE_VIEW_2;
// image 1 is in front of image 2 to begin
[self addSubview:imgView2];
[self addSubview:imgView1];
isOne = YES;
[imgView1 release];
[imgView2 release]; return self;
}- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
// Determine which view occupies which role
UIImageView *big = (UIImageView *)[self viewWithTag: (isOne ? IMAGE_VIEW_1 : IMAGE_VIEW_2)];
UIImageView *little = (UIImageView *)[self viewWithTag: (isOne ? IMAGE_VIEW_2 : IMAGE_VIEW_1)];
isOne = !isOne;
// Pack all the changes into the animation block
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0]; [big setFrame:SMALLRECT];
[big setAlpha:0.5];
[little setFrame:BIGRECT];
[little setAlpha:1.0];
[UIView commitAnimations];
// Hide the shrunken "big" image.
[big setAlpha:0.0f];
[[big superview] bringSubviewToFront:big];
}
@end@interface HelloController : UIViewController
@end@implementation HelloController
- (void)loadView
{
ToggleView *contentView = [[ToggleView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
contentView.backgroundColor = [UIColor whiteColor];
self.view = contentView;
[contentView release];
}
@end
@interface SampleAppDelegate : NSObject <UIApplicationDelegate>
@end@implementation SampleAppDelegate
- (void)applicationDidFinishLaunching:(UIApplication *)application {
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
HelloController *hello = [[HelloController alloc] init];
[window addSubview:hello.view];
[window makeKeyAndVisible];
}
@endint main(int argc, char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, @"SampleAppDelegate");
[pool release];
return retVal;
}
该范例相关资料可到我的博客参考