是一个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) IBOutlet UIImageView *ivMain;
@property (strong, nonatomic) IBOutlet UIImageView *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 {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
@try {
self.view.backgroundColor=[UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:1];
self.ivMain.highlighted=YES;
aryStrImageName=[NSArray arrayWithObjects:@"lijiang.jpg",@"qiao.jpg",@"shuangta.jpg",@"shui.jpg",@"xiangbi.jpg",nil];
iImageNumber=0;
if(aryStrImageName.count>0)
_ivMain.image=[UIImage imageNamed:aryStrImageName[0]];
self.ivMain.userInteractionEnabled=YES;
UITapGestureRecognizer *st=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ivMainTap:)];
[self.ivMain addGestureRecognizer: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 = [sender locationInView: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=[UIImage imageWithCGImage:imgrfDest];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)onBtnLastImageTouchUp:(id)sender {
if(--iImageNumber<0)
iImageNumber=aryStrImageName.count-1;
self.ivMain.image=[UIImage imageNamed:aryStrImageName[iImageNumber]];
_ivSubMain.image=nil;
}
- (IBAction)onBtnNextImageTouchUp:(UIButton *)sender {
iImageNumber=++iImageNumber%aryStrImageName.count;
self.ivMain.image=[UIImage imageNamed: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>