Created
March 1, 2012 00:16
-
-
Save egomez99/1945965 to your computer and use it in GitHub Desktop.
Pinch + Zoom
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var win = Titanium.UI.createWindow(); | |
var scrollView = Titanium.UI.createScrollView({ | |
contentWidth:'auto', | |
contentHeight:'auto', | |
height:'auto', | |
top:0, | |
bottom:50, | |
backgroundColor:'red', | |
showVerticalScrollIndicator:true, | |
showHorizontalScrollIndicator:true, | |
maxZoomScale:100, | |
minZoomScale:0.1, | |
animatedCenterPoint: [0.5, 0.5], | |
anchorPoint: [0.5, 0.5] | |
}); | |
var view = Ti.UI.createView({ | |
backgroundColor:'#336699', | |
borderRadius:10, | |
width:300, | |
height:500, | |
top:10, | |
anchorPoint: [0.5, 0.5] | |
}); | |
var label = Ti.UI.createLabel({ | |
font:{fontSize:18,fontWeight:'bold',fontFamily:'Helvetica Neue'}, | |
text:'Pinch or Zoom', | |
width:'auto', | |
height:'auto' | |
}); | |
view.add(label); | |
scrollView.add(view); | |
var messageView = Ti.UI.createView({ | |
backgroundColor:'black', | |
bottom:0, | |
height:50 | |
}); | |
var message = Ti.UI.createLabel({ | |
font:{fontSize:14,fontFamily:'Helvetica Neue'}, | |
color:'yellow', | |
width:'auto', | |
height:'auto' | |
}); | |
messageView.add(message); | |
win.add(scrollView); | |
win.add(messageView); | |
scrollView.addEventListener('scale',function(e) | |
{ | |
message.text = "Zoomed to scale: "+e.scale; | |
}); | |
scrollView.addEventListener('scroll',function(e) | |
{ | |
var a = win.height; | |
var b = win.width / 2; | |
message.text = "Scrolling to x:"+Math.round(e.x)+", y:"+Math.round(e.y); | |
Ti.API.info(a + ' - '+ b ); | |
view.top = a; | |
view.left = b; | |
view.height = 200; | |
view.width = 120; | |
}); | |
var bb = Titanium.UI.createButtonBar({ | |
labels:['+', '-'], | |
backgroundColor:'#336699', | |
top:50, | |
style:Titanium.UI.iPhone.SystemButtonStyle.BAR, | |
height:25, | |
width:100 | |
}); | |
win.setRightNavButton(bb); | |
bb.addEventListener('click',function(e) | |
{ | |
if (e.index === 0) | |
{ | |
scrollView.zoomScale = scrollView.scale+0.1; | |
} | |
else | |
{ | |
scrollView.zoomScale = scrollView.scale-0.1; | |
} | |
label.text = "Scale: "+scrollView.scale; | |
}); | |
win.open(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var win = Titanium.UI.createWindow(); | |
var scrollView = Titanium.UI.createScrollView({ | |
contentWidth:'auto', | |
contentHeight:'auto', | |
height:'auto', | |
top:0, | |
bottom:50, | |
backgroundColor:'red', | |
showVerticalScrollIndicator:true, | |
showHorizontalScrollIndicator:true, | |
maxZoomScale:100, | |
minZoomScale:0.1, | |
animatedCenterPoint: [0.5, 0.5], | |
anchorPoint: [0.5, 0.5] | |
}); | |
var view = Ti.UI.createView({ | |
backgroundColor:'#336699', | |
borderRadius:10, | |
width:300, | |
height:500, | |
top:10, | |
anchorPoint: [0.5, 0.5] | |
}); | |
var label = Ti.UI.createLabel({ | |
font:{fontSize:18,fontWeight:'bold',fontFamily:'Helvetica Neue'}, | |
text:'Pinch or Zoom', | |
width:'auto', | |
height:'auto' | |
}); | |
view.add(label); | |
scrollView.add(view); | |
var messageView = Ti.UI.createView({ | |
backgroundColor:'black', | |
bottom:0, | |
height:50 | |
}); | |
var message = Ti.UI.createLabel({ | |
font:{fontSize:14,fontFamily:'Helvetica Neue'}, | |
color:'yellow', | |
width:'auto', | |
height:'auto' | |
}); | |
messageView.add(message); | |
win.add(scrollView); | |
win.add(messageView); | |
scrollView.addEventListener('scale',function(e) | |
{ | |
message.text = "Zoomed to scale: "+e.scale; | |
}); | |
scrollView.addEventListener('scroll',function(e) | |
{ | |
var a = win.height; | |
var b = win.width / 2; | |
message.text = "Scrolling to x:"+Math.round(e.x)+", y:"+Math.round(e.y); | |
Ti.API.info(a + ' - '+ b ); | |
view.top = a; | |
view.left = b; | |
view.height = 200; | |
view.width = 120; | |
}); | |
var bb = Titanium.UI.createButtonBar({ | |
labels:['+', '-'], | |
backgroundColor:'#336699', | |
top:50, | |
style:Titanium.UI.iPhone.SystemButtonStyle.BAR, | |
height:25, | |
width:100 | |
}); | |
win.setRightNavButton(bb); | |
bb.addEventListener('click',function(e) | |
{ | |
if (e.index === 0) | |
{ | |
scrollView.zoomScale = scrollView.scale+0.1; | |
} | |
else | |
{ | |
scrollView.zoomScale = scrollView.scale-0.1; | |
} | |
label.text = "Scale: "+scrollView.scale; | |
}); | |
win.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment