Skip to content

Commit

Permalink
加入文本选择功能
Browse files Browse the repository at this point in the history
简单的文本选择
  • Loading branch information
Tigerwf authored and Tigerwf committed Jan 29, 2015
1 parent 349f1d0 commit f9d850c
Show file tree
Hide file tree
Showing 9 changed files with 541 additions and 7 deletions.
16 changes: 16 additions & 0 deletions WFReader.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
D20DC28F1A5FB6AB000EE995 /* r_drag-dot@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = D20DC28E1A5FB6AB000EE995 /* r_drag-dot@2x.png */; };
D22DE51E1A4C14A500E75F4E /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = D22DE51D1A4C14A500E75F4E /* main.m */; };
D22DE5211A4C14A500E75F4E /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = D22DE5201A4C14A500E75F4E /* AppDelegate.m */; };
D22DE5241A4C14A500E75F4E /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D22DE5231A4C14A500E75F4E /* ViewController.m */; };
Expand All @@ -28,6 +29,8 @@
D22DE5661A4C14C300E75F4E /* E_ReaderView.m in Sources */ = {isa = PBXBuildFile; fileRef = D22DE5551A4C14C300E75F4E /* E_ReaderView.m */; };
D22DE5671A4C14C300E75F4E /* E_ReaderViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D22DE5581A4C14C300E75F4E /* E_ReaderViewController.m */; };
D22DE5681A4C14C300E75F4E /* E_ScrollViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D22DE55A1A4C14C300E75F4E /* E_ScrollViewController.m */; };
D27768EF1A79F2F200607241 /* E_CursorView.m in Sources */ = {isa = PBXBuildFile; fileRef = D27768EE1A79F2F200607241 /* E_CursorView.m */; };
D27768F21A7A05D800607241 /* E_MagnifiterView.m in Sources */ = {isa = PBXBuildFile; fileRef = D27768F11A7A05D800607241 /* E_MagnifiterView.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -42,6 +45,7 @@

/* Begin PBXFileReference section */
D206F34C1A4C164300A50C29 /* E_ContantFile.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = E_ContantFile.h; sourceTree = "<group>"; };
D20DC28E1A5FB6AB000EE995 /* r_drag-dot@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "r_drag-dot@2x.png"; sourceTree = "<group>"; };
D22DE5181A4C14A500E75F4E /* WFReader.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WFReader.app; sourceTree = BUILT_PRODUCTS_DIR; };
D22DE51C1A4C14A500E75F4E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
D22DE51D1A4C14A500E75F4E /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -76,6 +80,10 @@
D22DE5581A4C14C300E75F4E /* E_ReaderViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = E_ReaderViewController.m; sourceTree = "<group>"; };
D22DE5591A4C14C300E75F4E /* E_ScrollViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = E_ScrollViewController.h; sourceTree = "<group>"; };
D22DE55A1A4C14C300E75F4E /* E_ScrollViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = E_ScrollViewController.m; sourceTree = "<group>"; };
D27768ED1A79F2F200607241 /* E_CursorView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = E_CursorView.h; sourceTree = "<group>"; };
D27768EE1A79F2F200607241 /* E_CursorView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = E_CursorView.m; sourceTree = "<group>"; };
D27768F01A7A05D800607241 /* E_MagnifiterView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = E_MagnifiterView.h; sourceTree = "<group>"; };
D27768F11A7A05D800607241 /* E_MagnifiterView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = E_MagnifiterView.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -186,6 +194,7 @@
D22DE54B1A4C14C300E75F4E /* resource */ = {
isa = PBXGroup;
children = (
D20DC28E1A5FB6AB000EE995 /* r_drag-dot@2x.png */,
D22DE54C1A4C14C300E75F4E /* Chapter1.txt */,
D22DE54D1A4C14C300E75F4E /* Chapter2.txt */,
D22DE54E1A4C14C300E75F4E /* Chapter3.txt */,
Expand All @@ -202,6 +211,10 @@
children = (
D22DE5541A4C14C300E75F4E /* E_ReaderView.h */,
D22DE5551A4C14C300E75F4E /* E_ReaderView.m */,
D27768ED1A79F2F200607241 /* E_CursorView.h */,
D27768EE1A79F2F200607241 /* E_CursorView.m */,
D27768F01A7A05D800607241 /* E_MagnifiterView.h */,
D27768F11A7A05D800607241 /* E_MagnifiterView.m */,
);
path = View;
sourceTree = "<group>";
Expand Down Expand Up @@ -303,6 +316,7 @@
D22DE5641A4C14C300E75F4E /* Chapter6.txt in Resources */,
D22DE5611A4C14C300E75F4E /* Chapter3.txt in Resources */,
D22DE5601A4C14C300E75F4E /* Chapter2.txt in Resources */,
D20DC28F1A5FB6AB000EE995 /* r_drag-dot@2x.png in Resources */,
D22DE55F1A4C14C300E75F4E /* Chapter1.txt in Resources */,
D22DE5621A4C14C300E75F4E /* Chapter4.txt in Resources */,
D22DE5631A4C14C300E75F4E /* Chapter5.txt in Resources */,
Expand All @@ -324,6 +338,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D27768EF1A79F2F200607241 /* E_CursorView.m in Sources */,
D22DE55B1A4C14C300E75F4E /* E_CommonManager.m in Sources */,
D22DE5671A4C14C300E75F4E /* E_ReaderViewController.m in Sources */,
D22DE55D1A4C14C300E75F4E /* E_Paging.mm in Sources */,
Expand All @@ -333,6 +348,7 @@
D22DE55E1A4C14C300E75F4E /* E_ReaderDataSource.m in Sources */,
D22DE5681A4C14C300E75F4E /* E_ScrollViewController.m in Sources */,
D22DE5211A4C14A500E75F4E /* AppDelegate.m in Sources */,
D27768F21A7A05D800607241 /* E_MagnifiterView.m in Sources */,
D22DE51E1A4C14A500E75F4E /* main.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
32 changes: 32 additions & 0 deletions WFReader/EReader/View/E_CursorView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// E_CursorView.h
// WFReader
//
// Created by 阿虎 on 15/1/29.
// Copyright (c) 2015年 tigerwf. All rights reserved.
//

#import <UIKit/UIKit.h>

/**
* 光标类
*/

typedef enum {
CursorLeft = 0,
CursorRight ,

} CursorType;

@interface E_CursorView : UIView
{
UIImageView *_dragDot;
}
@property (nonatomic,assign) CursorType direction;
@property (nonatomic,assign) float cursorHeight;
@property (nonatomic,retain) UIColor *cursorColor;
@property (nonatomic,assign) CGPoint setupPoint;

- (id)initWithType:(CursorType)type andHeight:(float)cursorHeight byDrawColor:(UIColor *)drawColor;

@end
62 changes: 62 additions & 0 deletions WFReader/EReader/View/E_CursorView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// E_CursorView.m
// WFReader
//
// Created by 阿虎 on 15/1/29.
// Copyright (c) 2015年 tigerwf. All rights reserved.
//

#import "E_CursorView.h"
#define kE_CursorWidth 2

@implementation E_CursorView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/

- (id)initWithType:(CursorType)type andHeight:(float)cursorHeight byDrawColor:(UIColor *)drawColor{
self = [super init];
if (self) {
_direction = type;
_cursorHeight = cursorHeight;
_cursorColor = drawColor;
self.clipsToBounds = NO;

}
return self;

}


- (void)setSetupPoint:(CGPoint)setupPoint{

self.backgroundColor = _cursorColor;

if (_dragDot) {
[_dragDot removeFromSuperview];
_dragDot = nil;
}

_dragDot = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"r_drag-dot.png"]];

if (_direction == CursorLeft) {
self.frame = CGRectMake(setupPoint.x - kE_CursorWidth, setupPoint.y - _cursorHeight, kE_CursorWidth, _cursorHeight);
_dragDot.frame = CGRectMake(-7, -8, 15, 17);

}else{
self.frame = CGRectMake(setupPoint.x, setupPoint.y - _cursorHeight, kE_CursorWidth, _cursorHeight);
_dragDot.frame = CGRectMake(-6, _cursorHeight - 8, 15, 17);
}
[self addSubview:_dragDot];
}

- (void)dealloc{


}
@end
19 changes: 19 additions & 0 deletions WFReader/EReader/View/E_MagnifiterView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// E_MagnifiterView.h
// WFReader
//
// Created by 阿虎 on 15/1/29.
// Copyright (c) 2015年 tigerwf. All rights reserved.
//

#import <UIKit/UIKit.h>

/**
* 放大镜类
*/
@interface E_MagnifiterView : UIView

@property (weak, nonatomic) UIView *viewToMagnify;
@property (nonatomic) CGPoint touchPoint;

@end
40 changes: 40 additions & 0 deletions WFReader/EReader/View/E_MagnifiterView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// E_MagnifiterView.m
// WFReader
//
// Created by 阿虎 on 15/1/29.
// Copyright (c) 2015年 tigerwf. All rights reserved.
//

#import "E_MagnifiterView.h"

@implementation E_MagnifiterView

- (id)initWithFrame:(CGRect)frame {

if (self = [super initWithFrame:CGRectMake(0, 0, 80, 80)]) {
self.layer.borderColor = [[UIColor lightGrayColor] CGColor];
self.layer.borderWidth = 1;
self.layer.cornerRadius = 40;
self.layer.masksToBounds = YES;
}
return self;
}

- (void)setTouchPoint:(CGPoint)touchPoint {

_touchPoint = touchPoint;
self.center = CGPointMake(touchPoint.x, touchPoint.y - 70);
[self setNeedsDisplay];
}

- (void)drawRect:(CGRect)rect {

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, self.frame.size.width * 0.5,self.frame.size.height * 0.5);
CGContextScaleCTM(context, 1.5, 1.5);
CGContextTranslateCTM(context, -1 * (_touchPoint.x), -1 * (_touchPoint.y));
[self.viewToMagnify.layer renderInContext:context];
}

@end
11 changes: 11 additions & 0 deletions WFReader/EReader/View/E_ReaderView.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,23 @@


#import <UIKit/UIKit.h>
#import "E_MagnifiterView.h"
#import "E_CursorView.h"

/**
* 显示文本类
*/

@interface E_ReaderView : UIView

@property(unsafe_unretained, nonatomic)NSUInteger font;
@property(copy, nonatomic)NSString *text;

@property (strong, nonatomic) E_CursorView *leftCursor;
@property (strong, nonatomic) E_CursorView *rightCursor;
@property (strong, nonatomic) E_MagnifiterView *magnifierView;


- (void)render;

@end
Loading

0 comments on commit f9d850c

Please sign in to comment.