Ios 钛合金,使用动画更改文本字段高度
在Appcelerator Titanium(iOS项目)中,我有一个高度为50的Ios 钛合金,使用动画更改文本字段高度,ios,titanium,appcelerator,Ios,Titanium,Appcelerator,在Appcelerator Titanium(iOS项目)中,我有一个高度为50的TextField。TextField包含更多的文本,但它的高度设置为50,这让我可以使用TextField作为剩余文本的预览:在TextField下,我有一个按钮,当我点击这个按钮时,我想显示整个文本,因此,我想将TextField从当前高度设置为Ti.UI.SIZE。这可能吗?怎么用?我注意到一些iOS属性(例如anchorPoint),但我不明白它们是否对我的情况有用。如果需要多行和换行,则需要使用TextA
TextField
。TextField
包含更多的文本,但它的高度设置为50,这让我可以使用TextField
作为剩余文本的预览:在TextField
下,我有一个按钮,当我点击这个按钮时,我想显示整个文本,因此,我想将TextField
从当前高度设置为Ti.UI.SIZE
。这可能吗?怎么用?我注意到一些iOS属性(例如anchorPoint),但我不明白它们是否对我的情况有用。如果需要多行和换行,则需要使用TextArea
而不是TextField
我已经将文本区域
添加到视图
中,这样我就可以对其进行动画处理,使其同时展开和收缩
你可以试试这样的
// Create the text area for multiple lines and word wrapping.
var messageField = Ti.UI.createTextArea({
backgroundColor: 'transparent',
color: 'black',
height: Ti.UI.SIZE, // Set here the height to SIZE and the view's height to the required one, ex. 50
textAlign: 'left',
value: 'This text should be displayed in more than one line in a text area, but that behavior is not supported by a text field, again, This text should be displayed in more than one line in a text area, but that behavior is not supported by a text field.',
verticalAlign: Ti.UI.TEXT_VERTICAL_ALIGNMENT_TOP,
width: '90%',
font: { fontSize: 20 }
});
// Add the text area to a view to be able to animate it
var view = Titanium.UI.createView({
height: 50, // Required height
top: 250,
width: '90%',
borderColor: 'black',
borderRadius: 10,
borderWidth: 2,
});
view.add(messageField);
// Create animation object
var animation = Titanium.UI.createAnimation();
animation.duration = 1000; // Set the time of animation, 1000 --> 1 second
var button = Ti.UI.createButton({
title: "Show More",
font: { fontSize: 18 },
width: 100,
top: 200
});
var isExpanded = false;
button.addEventListener('click', function() { // Event listener for your button
if(isExpanded) {
isExpanded = false;
animation.height = 50; // Set the animation height to 50 to shrink the view
view.animate(animation); // Start animating the view to the required height
button.title = "Show More";
} else {
isExpanded = true;
animation.height = Ti.UI.SIZE; // Set the animation height to SIZE to make it expand
view.animate(animation); // Start animating the view to the required height
button.title = "Show Less";
}
});
var win = Ti.UI.createWindow({
backgroundColor: 'white'
});
win.add(button);
win.add(view);
win.open();
这没关系,但我想要一个动画,而不是那样改变高度:-)@3000我已经添加了动画代码,如果你还需要什么,请尝试告诉我。这很有趣,但它会导致另一个问题:我得到的是文本的结尾,而不是开头,因此没有“预览”有效性我认为实现这种行为的唯一方法是将
TextArea
的scrollable
属性设置为false,但是用户在单击Show More按钮之前无法看到所有文本。在Tianium:D中经常会发生这种情况,我希望他们在下一个SDK中修复这种情况。