Skip to content

Commit

Permalink
Updated demo project, now using auto layout; removed unnecessary semi…
Browse files Browse the repository at this point in the history
…colons.
  • Loading branch information
yichizhang committed Aug 4, 2015
1 parent 648bf0e commit 77c5036
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Demo/Demo-Swift/Demo-Swift/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var tc = UITabBarController()

var vc1 = ViewController()
vc1.mode = JCDemoType.PDF;
vc1.mode = JCDemoType.PDF
vc1.tabBarItem = UITabBarItem(title: "PDF", image: DemoStyleKit.imageOf(string: "pdf"), selectedImage: nil)

var vc2 = ViewController()
Expand Down
4 changes: 2 additions & 2 deletions Demo/Demo-Swift/Demo-Swift/DemoAnnotationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import UIKit
}

override func sizeThatFits(size: CGSize) -> CGSize {
return CGSizeMake(max(imageView.image!.size.width,30), max(imageView.image!.size.height,30));
return CGSizeMake(max(imageView.image!.size.width,30), max(imageView.image!.size.height,30))
}

override func layoutSubviews() {

imageView.sizeToFit();
imageView.sizeToFit()
imageView.frame = imageView.bounds
}

Expand Down
2 changes: 1 addition & 1 deletion Demo/Demo-Swift/Demo-Swift/DemoStyleKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class DemoStyleKit : NSObject {

let textTextHeight: CGFloat = textTextContent.boundingRectWithSize(CGSizeMake(textRect.width, CGFloat.infinity), options: NSStringDrawingOptions.UsesLineFragmentOrigin, attributes: textFontAttributes, context: nil).size.height
CGContextSaveGState(context)
CGContextClipToRect(context, textRect);
CGContextClipToRect(context, textRect)
textTextContent.drawInRect(CGRectMake(textRect.minX, textRect.minY + (textRect.height - textTextHeight) / 2, textRect.width, textTextHeight), withAttributes: textFontAttributes)
CGContextRestoreGState(context)
}
Expand Down
55 changes: 30 additions & 25 deletions Demo/Demo-Swift/Demo-Swift/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ enum JCDemoType {
case Image
}

let annotationReuseIdentifier = "JCAnnotationReuseIdentifier";
let annotationReuseIdentifier = "JCAnnotationReuseIdentifier"
let SkippingGirlImageName = "SkippingGirl"
let SkippingGirlImageSize = CGSizeMake(432, 648)

Expand All @@ -36,29 +36,39 @@ let ButtonTitleRemoveAnnotation = "Remove this Annotation"
if(mode == JCDemoType.PDF){
scrollView = JCTiledPDFScrollView(frame: self.view.bounds, URL: NSBundle.mainBundle().URLForResource("Map", withExtension: "pdf")! )
}else{
scrollView = JCTiledScrollView(frame: self.view.bounds, contentSize: SkippingGirlImageSize);
scrollView = JCTiledScrollView(frame: self.view.bounds, contentSize: SkippingGirlImageSize)
}
scrollView.tiledScrollViewDelegate = self
scrollView.zoomScale = 1.0

scrollView.dataSource = self;
scrollView.tiledScrollViewDelegate = self;
scrollView.dataSource = self
scrollView.tiledScrollViewDelegate = self

scrollView.tiledView.shouldAnnotateRect = true;
scrollView.tiledView.shouldAnnotateRect = true

// totals 4 sets of tiles across all devices, retina devices will miss out on the first 1x set
scrollView.levelsOfZoom = 3;
scrollView.levelsOfDetail = 3;
scrollView.levelsOfZoom = 3
scrollView.levelsOfDetail = 3
scrollView.setTranslatesAutoresizingMaskIntoConstraints(false)
view.addSubview(scrollView)

let paddingX:CGFloat = 20;
let paddingY:CGFloat = 30;
infoLabel = UILabel(frame: CGRectMake(paddingX, paddingY, self.view.bounds.size.width - 2*paddingX, 30));
infoLabel = UILabel(frame: CGRectZero)
infoLabel.backgroundColor = UIColor.blackColor()
infoLabel.textColor = UIColor.whiteColor()
infoLabel.textAlignment = NSTextAlignment.Center
infoLabel.setTranslatesAutoresizingMaskIntoConstraints(false)
view.addSubview(infoLabel)

view.addConstraints([
NSLayoutConstraint(item: scrollView, attribute: .Width, relatedBy: .Equal, toItem: view, attribute: .Width, multiplier: 1, constant: 0),
NSLayoutConstraint(item: scrollView, attribute: .Height, relatedBy: .Equal, toItem: view, attribute: .Height, multiplier: 1, constant: 0),
NSLayoutConstraint(item: scrollView, attribute: .Top, relatedBy: .Equal, toItem: view, attribute: .Top, multiplier: 1, constant: 0),
NSLayoutConstraint(item: scrollView, attribute: .Leading, relatedBy: .Equal, toItem: view, attribute: .Leading, multiplier: 1, constant: 0),

NSLayoutConstraint(item: infoLabel, attribute: .Top, relatedBy: .Equal, toItem: view, attribute: .Top, multiplier: 1, constant: 20),
NSLayoutConstraint(item: infoLabel, attribute: .CenterX, relatedBy: .Equal, toItem: view, attribute: .CenterX, multiplier: 1, constant: 0),
])

addRandomAnnotations()
}

Expand All @@ -69,31 +79,26 @@ let ButtonTitleRemoveAnnotation = "Remove this Annotation"

func addRandomAnnotations() {
for index in 0...4 {
var a:JCAnnotation = DemoAnnotation();
var a:JCAnnotation = DemoAnnotation()
a.contentPosition = CGPointMake(
//This is ridiculous!! Hahaha
CGFloat(UInt(arc4random_uniform(UInt32(UInt(scrollView.tiledView.bounds.width))))),
CGFloat(UInt(arc4random_uniform(UInt32(UInt(scrollView.tiledView.bounds.height)))))
);
scrollView.addAnnotation(a);
)
scrollView.addAnnotation(a)
}
}

// MARK: JCTiledScrollView Delegate
func tiledScrollViewDidZoom(scrollView: JCTiledScrollView) {

let infoString = "zoomScale=\(scrollView.zoomScale)"

infoLabel.text = infoString
infoLabel.text = NSString(format: "zoomScale=%.2f", scrollView.zoomScale) as String
}

func tiledScrollView(scrollView: JCTiledScrollView, didReceiveSingleTap gestureRecognizer: UIGestureRecognizer) {

var tapPoint:CGPoint = gestureRecognizer.locationInView(scrollView.tiledView)

let infoString = "(\(tapPoint.x), \(tapPoint.y)), zoomScale=\(scrollView.zoomScale)"

infoLabel.text = infoString
infoLabel.text = NSString(format: "(%.2f, %.2f), zoomScale=%.2f", tapPoint.x, tapPoint.y, scrollView.zoomScale) as String
}

func tiledScrollView(scrollView: JCTiledScrollView, didSelectAnnotationView view: JCAnnotationView) {
Expand All @@ -108,16 +113,16 @@ let ButtonTitleRemoveAnnotation = "Remove this Annotation"

func tiledScrollView(scrollView: JCTiledScrollView!, viewForAnnotation annotation: JCAnnotation!) -> JCAnnotationView! {

var view:DemoAnnotationView? = scrollView.dequeueReusableAnnotationViewWithReuseIdentifier(annotationReuseIdentifier) as? DemoAnnotationView;
var view:DemoAnnotationView? = scrollView.dequeueReusableAnnotationViewWithReuseIdentifier(annotationReuseIdentifier) as? DemoAnnotationView

if ( (view) == nil )
{
view = DemoAnnotationView(frame:CGRectZero, annotation:annotation, reuseIdentifier:"Identifier");
view!.imageView.image = UIImage(named: "marker-red.png");
view!.sizeToFit();
view = DemoAnnotationView(frame:CGRectZero, annotation:annotation, reuseIdentifier:"Identifier")
view!.imageView.image = UIImage(named: "marker-red.png")
view!.sizeToFit()
}

return view;
return view
}

func tiledScrollView(scrollView: JCTiledScrollView, imageForRow row: Int, column: Int, scale: Int) -> UIImage! {
Expand Down

0 comments on commit 77c5036

Please sign in to comment.