zoukankan      html  css  js  c++  java
  • iOS:图像和点击事件

    问题:如何区分点的是哪张图片?

    //
    //  main.m
    //  Hello
    //
    //  Created by lishujun on 14-8-28.
    //  Copyright (c) 2014年 lishujun. All rights reserved.
    //
    
    #import <UIKit/UIKit.h>
    
    
    // 视图控制器对象
    @interface HelloWorldViewController : UIViewController
    @end
    
    @implementation HelloWorldViewController
    
    -(void) loadView
    {
        //创建视图对象
        UIView *contentView = [[UIView alloc]initWithFrame:[[UIScreen mainScreen] applicationFrame]];
        contentView.backgroundColor = [UIColor lightGrayColor];
        self.view = contentView;
        
        UIImageView *imageView =[[UIImageView alloc]initWithFrame:CGRectMake(70, 100, 100, 100)];
        imageView.image = [UIImage imageNamed:@"100.png"];
        imageView.userInteractionEnabled = YES;
        UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(UesrClicked:)];
        [imageView addGestureRecognizer:singleTap];
        
        UIImageView *imageView2 =[[UIImageView alloc]initWithFrame:CGRectMake(70, 240, 100, 100)];
        imageView2.image = [UIImage imageNamed:@"100.png"];
        imageView2.userInteractionEnabled = YES;
        UITapGestureRecognizer *singleTap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(UesrClicked:)];
        [imageView2 addGestureRecognizer:singleTap2];
        
        [contentView addSubview:imageView];
        [contentView addSubview:imageView2];
    }
    
    -(void) UesrClicked:(id)sender
    {
        //NSLog(@"%@", ((UIImageView*)((UITapGestureRecognizer *)sender).view).image);
        NSLog(@"%@",sender);
    }
    
    @end
    
    
    // 委托对象
    @interface HelloWorldAppDelegate : NSObject <UIApplicationDelegate>
    {
        IBOutlet UIWindow *window;
    }
    
    @property (nonatomic, retain) UIWindow *window;
    //必须声明为属性,声明为局部变量则无法绘制视图,显示为黑屏
    @end
    
    @implementation HelloWorldAppDelegate
    @synthesize window;
    
    -(void) applicationDidFinishLaunching:(UIApplication *)application
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
        HelloWorldViewController *viewController = [[HelloWorldViewController alloc]init];
        self.window.rootViewController = viewController;
        [self.window makeKeyAndVisible];
    }
    
    @end
    
    // 程序入口
    int main(int argc, char * argv[])
    {
        @autoreleasepool {
            return UIApplicationMain(argc, argv, nil, @"HelloWorldAppDelegate");
        }
    }
  • 相关阅读:
    微软认证考试考试 MCTS, MCITP, MCPD 享受9折优惠
    为程序中按钮添加Shield图标
    WinHEC 2008 China Windows 7 体验之蓝屏无罪
    我们像热爱生命一样热爱技术-洛杉矶Windows硬件工程大会
    WinHEC 之盖茨编年史期待 WinHEC 2008 China
    新年伊始 {阿猫阿狗的幸福生活系列} [一]
    通过数据库备份还原 TFS 到新服务器
    为托管应用程序添加DPI Aware支持
    轻松制作Windows Vista/Windows 7系统WIM镜像
    VSTS报表自定义之Bug重现频率报表
  • 原文地址:https://www.cnblogs.com/code-style/p/3952702.html
Copyright © 2011-2022 走看看