iOS 点击图片放大Demo

创建UIImageView类目

添加一个方法

代码如下:

.h

#import <Foundation/Foundation.h>


@interface UIImageView (UIImageViewEx)


- (void)addDetailShow;


@end


.m

#define kCoverViewTag           1234

#define kImageViewTag           1235

#define kAnimationDuration      0.3f

#define kImageViewWidth         300.0f

#define kBackViewColor          [UIColor colorWithWhite:0.667 alpha:1.f]


#import "UIImageView+Addition.h"


@implementation UIImageView (UIImageViewEx)


- (void)hiddenView

{

    UIView *coverView = (UIView *)[[self window] viewWithTag:kCoverViewTag];

    [coverView removeFromSuperview];

}


- (void)hiddenViewAnimation

{    

    UIImageView *imageView = (UIImageView *)[[self window] viewWithTag:kImageViewTag];

    

    [UIView beginAnimations:nil context:nil];    

    [UIView setAnimationDuration:kAnimationDuration]; //动画时长

    CGRect rect = [self convertRect:self.bounds toView:self.window];

    imageView.frame = rect;

    

    [UIView commitAnimations];

    [self performSelector:@selector(hiddenView) withObject:nil afterDelay:kAnimationDuration];

    

}


//自动按原UIImageView等比例调整目标rect

- (CGRect)autoFitFrame

{

    //调整为固定宽,高等比例动态变化

    float width = kImageViewWidth;

    float targeHeight = (width*self.frame.size.height)/self.frame.size.width;

    UIView *coverView = (UIView *)[[self window] viewWithTag:kCoverViewTag];

    CGRect targeRect = CGRectMake(coverView.frame.size.width/2 - width/2, coverView.frame.size.height/2 - targeHeight/2, width, targeHeight);

    return targeRect;

}


- (void)imageTap

{    

    UIView *coverView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    coverView.backgroundColor = kBackViewColor;

    coverView.tag = kCoverViewTag;

    UITapGestureRecognizer *hiddenViewGecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hiddenViewAnimation)];

    [coverView addGestureRecognizer:hiddenViewGecognizer];

    [hiddenViewGecognizer release];

    

    UIImageView *imageView = [[UIImageView alloc] initWithImage:self.image];

    imageView.tag = kImageViewTag;

    imageView.userInteractionEnabled = YES;

    imageView.contentMode = self.contentMode;

    CGRect rect = [self convertRect:self.bounds toView:self.window];

    imageView.frame = rect;

       

    [coverView addSubview:imageView];

    [[self window] addSubview:coverView];

    [coverView release];

    

    [UIView beginAnimations:nil context:nil];

    [UIView setAnimationDuration:kAnimationDuration];    

    imageView.frame = [self autoFitFrame]; 

    [UIView commitAnimations];

     

}


- (void)addDetailShow

{

    self.userInteractionEnabled = YES;

    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTap)];

    [self addGestureRecognizer:tapGestureRecognizer];

    [tapGestureRecognizer release];

}


@end

===================================

使用的时候 导入类目 直接添加这个addDetailShow方法就ok

如下:

 UIImageView *imageView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_photo.png"]];

    imageView2.frame = CGRectMake(100, 300, 100, 100);

    

    //类目添加了这个方法 可以实现图片放大

    [imageView2 addDetailShow];

    [self.view addSubview:imageView2];

    [imageView2 release];



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
iOS开发中实现Twitter登录功能的Demo可以按照以下步骤进行: 1. 首先,在Twitter开发者网站上创建一个应用,获取应用的API Key和Secret Key,并将它们添加到项目的Info.plist文件的URL schemes和URL whitelist中。 2. 在AppDelegate中导入Twitter框架并添加以下代码: ```swift import TwitterKit func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { TWTRTwitter.sharedInstance().start(withConsumerKey: "YOUR_API_KEY", consumerSecret: "YOUR_API_SECRET") return true } ``` 3. 在需要实现登录的ViewController中导入Twitter框架并添加以下代码: ```swift import TwitterKit @IBAction func twitterLoginButtonTapped(_ sender: UIButton) { TWTRTwitter.sharedInstance().logIn { (session, error) in if (session != nil) { print("Twitter login successful with user ID: \(session!.userID)") } else { print("Twitter login error: \(error!.localizedDescription)") } } } ``` 在上述代码中,当用户点击Twitter登录按钮时,调用`TWTRTwitter.sharedInstance().logIn`方法会打开Twitter登录界面,用户在该界面上登录成功后,会返回一个session,其中包含用户的userID和token等信息。根据返回的session是否为nil,判断登录是否成功。 注意:在使用此Demo之前,需要在项目的Build Settings中的Other Linker Flags添加`-ObjC`标志,否则可能会出现链接错误。 以上就是实现Twitter登录功能的iOS开发Demo

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值