我的第一个有点意思的IOS工程 - 图片局部放大
来源:互联网 发布:知乎是什么软件 编辑:程序博客网 时间:2024/04/29 11:18
是一个sva工程,现在可以把图片局部放大4倍,后期有时间了加上新的控制和设置部分
//
// ViewController.h
// sva_10_7_1
//
// Created by 李吉 on 15/9/4.
// Copyright (c) 2015年李吉. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ViewController :UIViewController
{
NSArray *aryStrImageName;
NSInteger iImageNumber;
UIGestureRecognizer *gr;
}
@property (strong,nonatomic) IBOutletUIImageView *ivMain;
@property (strong,nonatomic) IBOutletUIImageView *ivSubMain;
- (IBAction)onBtnLastImageTouchUp:(id)sender;
- (IBAction)onBtnNextImageTouchUp:(UIButton *)sender;
- (IBAction)onBtnVaguerImageTouchUp:(UIButton *)sender;
- (IBAction)onBtnObviouserTouchUp:(UIButton *)sender;
@end
//
// ViewController.m
// sva_10_7_1
//
// Created by 李吉 on 15/9/4.
// Copyright (c) 2015年李吉. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
@try {
self.view.backgroundColor=[UIColorcolorWithRed:0.2green:0.2blue:0.2alpha:1];
self.ivMain.highlighted=YES;
aryStrImageName=[NSArrayarrayWithObjects:@"lijiang.jpg",@"qiao.jpg",@"shuangta.jpg",@"shui.jpg",@"xiangbi.jpg",nil];
iImageNumber=0;
if(aryStrImageName.count>0)
_ivMain.image=[UIImageimageNamed:aryStrImageName[0]];
self.ivMain.userInteractionEnabled=YES;
UITapGestureRecognizer *st=[[UITapGestureRecognizeralloc] initWithTarget:selfaction:@selector(ivMainTap:)];
[self.ivMainaddGestureRecognizer:st];
_ivSubMain.contentMode=UIViewContentModeScaleToFill;
_ivMain.contentMode=UIViewContentModeScaleToFill;
_ivSubMain.image=nil;
}
@catch (NSException *exception) {
NSLog(@"%@\n",exception.reason);
}
@finally {
}
}
//将触摸点的图像放大,显示在ivSubMain控件上
-(IBAction)ivMainTap:(UIGestureRecognizer *)sender
{
bool bIsTouchValid=YES;
NSUInteger uiWidthInImage=(_ivMain.image.size.width/_ivMain.frame.size.width)*50;
NSUInteger uiHeightInImage=(_ivMain.image.size.height/_ivMain.frame.size.height)*50;
CGPoint ptTouch = [senderlocationInView:self.ivMain];
CGFloat fX=(ptTouch.x-25)*(_ivMain.image.size.width/_ivMain.frame.size.width);
CGFloat fY=(ptTouch.y-25)*(_ivMain.image.size.height/_ivMain.frame.size.height);
if(ptTouch.x-25<0||ptTouch.x+25>300)
bIsTouchValid=NO;
if(ptTouch.y-25<0||ptTouch.y+25>300)
bIsTouchValid=NO;
if(!bIsTouchValid)
self.ivSubMain.image=nil;
else
{
CGImageRef imgrfOrigin=_ivMain.image.CGImage;
CGImageRef imgrfDest=CGImageCreateWithImageInRect(imgrfOrigin,CGRectMake(fX, fY, uiWidthInImage, uiHeightInImage));
_ivSubMain.contentMode=UIViewContentModeScaleToFill;
_ivSubMain.image=[UIImageimageWithCGImage:imgrfDest];
}
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)onBtnLastImageTouchUp:(id)sender {
if(--iImageNumber<0)
iImageNumber=aryStrImageName.count-1;
self.ivMain.image=[UIImageimageNamed:aryStrImageName[iImageNumber]];
_ivSubMain.image=nil;
}
- (IBAction)onBtnNextImageTouchUp:(UIButton *)sender {
iImageNumber=++iImageNumber%aryStrImageName.count;
self.ivMain.image=[UIImageimageNamed:aryStrImageName[iImageNumber]];
_ivSubMain.image=nil;
}
- (IBAction)onBtnVaguerImageTouchUp:(UIButton *)sender {
_ivMain.alpha-=0.1;
if(_ivMain.alpha<0)
_ivMain.alpha=0;
_ivSubMain.alpha=_ivMain.alpha;
}
- (IBAction)onBtnObviouserTouchUp:(UIButton *)sender {
_ivMain.alpha+=0.1;
if(_ivMain.alpha>1)
_ivMain.alpha=1;
_ivSubMain.alpha=_ivMain.alpha;
}
@end
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7531" systemVersion="14D2134" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7520"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="ufC-wZ-h7g">
<objects>
<viewController id="vXZ-lx-hvc" customClass="ViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="jyV-Pf-zRb"/>
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="mKW-vM-RAo">
<rect key="frame" x="87" y="447" width="200" height="200"/>
</imageView>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="jA4-7F-tDK">
<rect key="frame" x="26" y="50" width="50" height="30"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.46788990825688076" alpha="1" colorSpace="calibratedRGB"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<state key="normal" title="上一张">
<color key="titleColor" red="1" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="onBtnLastImageTouchUp:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="b3q-WK-1OX"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="7FY-Zf-9Bn">
<rect key="frame" x="116" y="50" width="50" height="30"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.46788990825688076" alpha="1" colorSpace="calibratedRGB"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<state key="normal" title="下一张">
<color key="titleColor" red="1" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="onBtnNextImageTouchUp:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="FqY-Iy-fbt"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="oFa-Jf-LMp">
<rect key="frame" x="206" y="50" width="50" height="30"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.46788990825688076" alpha="1" colorSpace="calibratedRGB"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<state key="normal" title="变 淡">
<color key="titleColor" red="1" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="onBtnVaguerImageTouchUp:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="t8k-vI-Nak"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Ffg-bT-hun">
<rect key="frame" x="296" y="50" width="50" height="30"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.46788990825688076" alpha="1" colorSpace="calibratedRGB"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<state key="normal" title="增 强">
<color key="titleColor" red="1" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="onBtnObviouserTouchUp:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="SSb-UJ-LRf"/>
</connections>
</button>
<imageView contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" image="xiangbi.jpg" translatesAutoresizingMaskIntoConstraints="NO" id="PeG-Xu-JJG">
<rect key="frame" x="37" y="119" width="300" height="300"/>
</imageView>
</subviews>
<color key="backgroundColor" red="0.0" green="0.12232415902140673" blue="0.11926605504587151" alpha="1" colorSpace="calibratedRGB"/>
</view>
<simulatedScreenMetrics key="simulatedDestinationMetrics" type="retina47"/>
<connections>
<outlet property="ivMain" destination="PeG-Xu-JJG" id="7yj-Bj-nxg"/>
<outlet property="ivSubMain" destination="mKW-vM-RAo" id="PgT-FZ-oC9"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
</objects>
</scene>
</scenes>
<resources>
<image name="xiangbi.jpg" width="1024" height="768"/>
</resources>
</document>
- 我的第一个有点意思的IOS工程 - 图片局部放大
- 我的第一个程序------有点曲折
- 我的第一个Go网络程序,有点不完美
- 我做的第一个工程
- 我的第一个maven web工程
- 我的第一个mvc工程
- 我的第一个strust工程
- 我的第一个hebnate工程
- 图片的局部放大的效果实现
- js 实现 图片的局部放大效果
- js、jquery图片的局部放大
- 我写的第一个图片爬虫
- 分享以个DFS的程序--有点意思
- 我的第一个iOS App
- 我的第一个iOS Demo
- 局部放大的功能
- 有点意思的宏替换
- 一道有点意思的题
- hdu1976
- [Socket] Connect失败,显示Connection refused
- 用Hello World校验Docker的安装
- 安卓开发获取屏幕像素和密度
- eclipse sdk路径问题
- 我的第一个有点意思的IOS工程 - 图片局部放大
- 白酒烫着喝会降低甲醇的沸点
- 动画曲线转换成C#脚本
- CentOS下搭建JRE环境
- 第二周项目0-宣告“主权”
- stdcall
- Java学习笔记
- 外网访问本机调试的VS2008 C#网站
- java命名规范