如何在iPhone上用手指滑动/触摸动作绘制平滑线?我有以下代码,但它不顺利.例如,当我尝试做一个圆圈时,它会转弯.我想我必须使用OpenGL.有任何想法吗?示例代码?教程?
谢谢!
UIGraphicsBeginImageContext(self.view.frame.size);
[drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(), YES);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Run Code Online (Sandbox Code Playgroud) 你有一个想法,动画猫如何移动更顺畅?
这是口吃,我不知道如何设置它更顺畅.jQuery.fx.interval没有帮助
http://christianhaller.com/jquery-animate-img.html
thx,christian
我有一个显示方形项目的QListView.我的问题是,当我滚动这个列表时,它一次滚动一整行方块,我认为这看起来不对.相反,我希望列表一次滚动1个像素或两个 - 即平滑.这主要是化妆品的变化.知道我该怎么做吗?
我正在用Java制作一个简单的动画,我试图让它尽可能顺利.
我只使用每个Shape对象的*.Double内部类,并在Graphics2D对象中设置抗锯齿.只要我只使用fill()方法,但是如果我也使用draw()方法在同一个Shape周围绘制线条,那么这些线条的动画都是不连续的 - 逐个像素.
画布上的每个矩形都有这种绘制方法.它每20ms移动一次,整个画布使用Timer和TimerListener重新绘制.
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class AnimationTest {
public static void main(String[] args) {
JFrame frm = new JFrame("Test");
frm.setBounds(200, 200, 400, 400);
frm.setResizable(false);
frm.setLocationRelativeTo(null);
AnimationCanvas a = new AnimationCanvas();
frm.add(a);
frm.setVisible(true);
a.startAnimation();
}
}
class AnimationCanvas extends JPanel {
SimpleSquare[] squares = new SimpleSquare[2];
AnimationCanvas() {
squares[0] = new SimpleSquare(50, 80, true);
squares[1] = new SimpleSquare(160, 80, false);
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
for (SimpleSquare c : …Run Code Online (Sandbox Code Playgroud) 我只是在测试下面的代码以在UIImage上转弯:
- (UIImage *)makeRoundedImage:(UIImage *)image radius:(float)radius;
{
CALayer *imageLayer = [CALayer layer];
imageLayer.frame = CGRectMake(0, 0, image.size.width, image.size.height);
imageLayer.contents = (id) image.CGImage;
imageLayer.masksToBounds = YES;
imageLayer.cornerRadius = radius;
UIGraphicsBeginImageContext(image.size);
[imageLayer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *roundedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return roundedImage;
}
Run Code Online (Sandbox Code Playgroud)
除非您仔细查看生成的图像,否则我看起来还不错。拐角不光滑。如何使拐角更光滑/更柔软?
编辑:
石英圆角处理后的图像:

就像你可以看到角落不光滑。
这个版本带有UIImageView的cornerRadius,更加平滑。

渔获物在哪里?
是否可以平滑地为多个按钮制作淡出动画?
创建fadeout.xml @res/anim
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="1500"
android:repeatCount="infinite" />
</set>
Run Code Online (Sandbox Code Playgroud)
使用它来设置动画
Animation fadeout = AnimationUtils.loadAnimation(this, R.anim.fadeout);
Run Code Online (Sandbox Code Playgroud)
单击后将动画应用于某些按钮
public void click (View v){
button1.startAnimation(fadeout);
button2.startAnimation(fadeout);
button3.startAnimation(fadeout);
button4.startAnimation(fadeout);
button5.startAnimation(fadeout);
button6.startAnimation(fadeout);
button7.startAnimation(fadeout);
button8.startAnimation(fadeout);
button9.startAnimation(fadeout);
button10.startAnimation(fadeout);
button11.startAnimation(fadeout);
button12.startAnimation(fadeout);
button13.startAnimation(fadeout);
button14.startAnimation(fadeout);
button15.startAnimation(fadeout);
}
Run Code Online (Sandbox Code Playgroud)
应用到 3-5 个按钮时这不是问题,但是当应用到许多像上面这样的按钮时,它会变得滞后。
那么有没有办法让这个动画应用到许多按钮而不会滞后?
因为我需要将此动画应用到许多按钮上,大约 162 个按钮。
我正在使用 Galaxy Nexus 进行测试。
我正在用css和jquery做一个"图像库",我想通过点击按钮在图像之间切换.我已经完成了删除/添加类,因为它更容易,我知道我可以用"动画"来做,但它对我来说非常复杂.
我不想使用预先制作的滑块,所以,如果你可以帮助我,我会吝啬!
的jsfiddle:
我希望这样的事情是可能的:
$("something").addClass("someclass",1000); /* i mean adding ,1000 */
Run Code Online (Sandbox Code Playgroud) 我的网页中有一个 html5 画布。我只在其中放了一个图像和一个渐变。
Canvas 使用 thic JS 代码来绘制自己:
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
ctx.clearRect ( 0 , 0 , canvas.width, canvas.height );
var img = document.getElementById("slika");
ctx.drawImage(img, 0, 0,canvas.width,canvas.height);
var grd = ctx.createLinearGradient(x-400, 0, x, 0)
grd.addColorStop(0.3,"hsla(360, 100%, 100%, 0)");
grd.addColorStop(1,"hsla(360, 100%, 100%, 0.8)");
ctx.fillStyle=grd;
ctx.fillRect(0,0,canvas.width,canvas.height);
ctx.font = "70px Arial";
ctx.fillStyle = "black"
ctx.textAlign = "right";
ctx.fillText(textInput,canvas.width-50,canvas.height-120);
Run Code Online (Sandbox Code Playgroud)
当它显示时,过渡不是很平滑,它只是从某处开始并在某处结束。
它看起来像这样:

我希望过渡更平滑(我不是说更宽的梯度)。
有没有办法做到这一点?
谢谢回答。
下面的代码在 UIImageView 上绘制点之间的直线。绘图渲染速度快,看起来不错,但可能会更好,所以我想修改代码以创建平滑的曲线。在过去的六周里,我在 Swift 中研究了许多示例,但成功率为零。
我必须修改以下代码的哪些部分(以及如何)来实现这一点?有人告诉我调用下面的代码片段而不是 CGContextAddLineToPoint() (在下面的 // 2 处)应该可以解决问题,但我不清楚如何调用它以及它如何与当前代码完全相关。
片段:
func drawQuadLineWithPoints(firstPoint: CGPoint, secondPoint: CGPoint, thirdPoint: CGPoint, inContext: CGContext) {
CGContextMoveToPoint(context, 0.5 * (firstPoint.x + secondPoint.x), 0.5 * (firstPoint.y + secondPoint.y));
CGContextAddQuadCurveToPoint(context, secondPoint.x, secondPoint.y, 0.5 * (secondPoint.x + thirdPoint.x), 0.5 * (secondPoint.y + thirdPoint.y));
}
Run Code Online (Sandbox Code Playgroud)
代码:
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
swiped = false
if let touch = touches.anyObject() as? UITouch {
lastPoint = touch.locationInView(self.view)
}
}
func drawLineFrom(fromPoint: CGPoint, toPoint: CGPoint) {
// 1 …Run Code Online (Sandbox Code Playgroud) smooth默认情况下,Matlab的功能使用5点移动平均值来平滑数据.在python中做同样的事情的最佳方法是什么?例如,如果这是我的数据
0
0.823529411764706
0.852941176470588
0.705882352941177
0.705882352941177
0.676470588235294
0.676470588235294
0.500000000000000
0.558823529411765
0.647058823529412
0.705882352941177
0.705882352941177
0.617647058823529
0.705882352941177
0.735294117647059
0.735294117647059
0.588235294117647
0.588235294117647
1
0.647058823529412
0.705882352941177
0.764705882352941
0.823529411764706
0.647058823529412
0.735294117647059
0.794117647058824
0.794117647058824
0.705882352941177
0.676470588235294
0.794117647058824
0.852941176470588
0.735294117647059
0.647058823529412
0.647058823529412
0.676470588235294
0.676470588235294
0.529411764705882
0.676470588235294
0.794117647058824
0.882352941176471
0.735294117647059
0.852941176470588
0.823529411764706
0.764705882352941
0.558823529411765
0.588235294117647
0.617647058823529
0.647058823529412
0.588235294117647
0.617647058823529
0.647058823529412
0.794117647058824
0.823529411764706
0.647058823529412
0.617647058823529
0.647058823529412
0.676470588235294
0.764705882352941
0.676470588235294
0.647058823529412
0.705882352941177
0.764705882352941
0.705882352941177
0.500000000000000
0.529411764705882
0.529411764705882
0.647058823529412
0.676470588235294
0.588235294117647
0.735294117647059
0.794117647058824
0.852941176470588
0.764705882352941
Run Code Online (Sandbox Code Playgroud)
平滑的数据应该是
0
0.558823529411765
0.617647058823530
0.752941176470588 …Run Code Online (Sandbox Code Playgroud) smooth ×10
animation ×2
draw ×2
html ×2
iphone ×2
jquery ×2
android ×1
canvas ×1
css ×1
fadeout ×1
gradient ×1
graphics2d ×1
ios ×1
java ×1
line ×1
matlab ×1
numpy ×1
opengl-es ×1
python ×1
qlistview ×1
scipy ×1
scroll ×1
swift ×1
timer ×1
transition ×1
transitions ×1
uiimage ×1
uiimageview ×1