如何将按钮旋转360度持续30秒,之后按钮停止旋转.
我想做一件非常简单的事,但我无法弄清楚如何;
NSInteger * a=10;
a=a-1;
NSlog(@"a=%d",a);
Run Code Online (Sandbox Code Playgroud)
出于某种原因,它正在显示a=6.
怎么会这样?
在这段代码中
for (int i=0;i<3;i++) {
CGContextAddLineToPoint(context, self.xShift+15+self.rectLen*self.width+self.rectLen*(i+1), self.yShift+self.rectLen*10);
CGContextAddLineToPoint(context, self.xShift+15+self.rectLen*self.width+self.rectLen*(i+1), self.yShift+self.rectLen*10+self.rectLen);
CGContextAddLineToPoint(context, self.xShift+15+self.rectLen*self.width+self.rectLen*i, self.yShift+self.rectLen*10+self.rectLen);
CGContextAddLineToPoint(context, self.xShift+15+self.rectLen*self.width+self.rectLen*i, self.yShift+self.rectLen*10);
CGContextMoveToPoint(context, self.xShift+15+self.rectLen*self.width+self.rectLen*i, self.yShift+self.rectLen*10);
}
CGContextAddLineToPoint(context, self.xShift+15+self.rectLen*self.width+self.rectLen*4, self.yShift+self.rectLen*10);
CGContextAddLineToPoint(context, self.xShift+15+self.rectLen*self.width+self.rectLen*4, self.yShift+self.rectLen*10+self.rectLen);
CGContextAddLineToPoint(context, self.xShift+15+self.rectLen*self.width+self.rectLen*3, self.yShift+self.rectLen*10+self.rectLen);
CGContextAddLineToPoint(context, self.xShift+15+self.rectLen*self.width+self.rectLen*3, self.yShift+self.rectLen*10);
[[UIColor cyanColor] setFill];
[[UIColor blackColor] setStroke];
CGContextSetLineWidth(context, 1);
CGContextDrawPath(context, kCGPathStroke);
Run Code Online (Sandbox Code Playgroud)
使用setFill方法的行不起作用.这可能是什么问题?代码位于drawRect:方法中
我有自定义UIView绘图drawRect.
我不太了解C API,所以我不确定它们需要什么内存规则.Objective-C规则非常简单,并声明您通过init retain或者copyC语言功能CGGradientCreateWithColorComponents不是Objective-C而释放您拥有的任何内容,而产品>分析报告它是潜在的泄漏.
是否有必要发布此功能的结果,如果是,如何?一般来说,当涉及到这些API时,有没有简单的方法来了解函数是否正在分配您需要手动释放的内存?
更新:这是代码,感谢到目前为止答案中的信息.我现在收到incorrect decrement错误:
CGGradientRef theGradient=[self makeGradient:YES];
//do something with theGradient in my drawing
CGGradientRelease(theGradient); // this line Analyze says incorrect decrement of object not owned by caller
Run Code Online (Sandbox Code Playgroud)
在makeGradient我有:
- (CGGradientRef)makeGradient:(BOOL)red{
CGGradientRef gradient;
//create my gradient
return gradient;
}
Run Code Online (Sandbox Code Playgroud) 我正在使用Xcode 4.2并在编写通用应用程序的过程中.我从一个新项目开始时选择了SingleView Application模板.XCode添加了ViewController1.h,ViewController1.m,ViewController1_iphone.xib和ViewController1_iPad.xib.我需要添加更多UI并单击File ... New ... New File并选择UIViewController subClass模板并看到两个复选框(针对iPad,使用Xib进行用户界面).
我应该怎么做才能支持iPad和iPhone,同时拥有共享相同代码的常见.h和.m文件.我是否需要在视图控制器中添加代码以检查它是iPad还是iPhone?
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
} else {
}
Run Code Online (Sandbox Code Playgroud)
另外,我看到有人在谈论~iPad和~iPhone.这是怎么回事?
如果我理解正确,由于屏幕尺寸不同,我是否必须分别为iPad和iPhone设计UI?
我在这里完全糊涂了.
请帮忙.
我NSURL在ScanViewController课堂上有一个对象并将它传递给ListViewController类.
NSURL *url = [NSURL URLWithString:@"http:// some url"];
Run Code Online (Sandbox Code Playgroud)
我在我的项目中使用xib,但找不到替代品
[self.storyboard instantiateViewControllerWithIdentifier:]
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
{
if(error || !data)
{
NSLog(@"JSON NOT posted");
}
else
{
NSLog(@"JSON data posted!");
id jsonObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:Nil];
if([jsonObject respondsToSelector:@selector(objectForKey:)])
{
NSDictionary *dictionaryForUserID = [jsonObject valueForKey:@"ProjID"];
NSLog(@" Project Id = %@", dictionaryForUserID);
NSURL *urlToDisplayInListView = [NSURL URLWithString:[NSString stringWithFormat:@"http://some url/%@", dictionaryForUserID]]; **//Pass this object to other viewcontroller**
}
}
}];
Run Code Online (Sandbox Code Playgroud) 我需要显示两个发射信号的点.表示信号的方式是我们在Mac中常见的wifi信号强度指示器.
但是,有一些变化:

我可以通过覆盖View类的drawRect来获取附加的图像:
CGContext context = UIGraphics.GetCurrentContext();
context.SetLineWidth(2.0f);
UIColor color = UIColor.FromRGB(65, 137, 77);
context.SetStrokeColorWithColor(color.CGColor);
float maxRadius = rect.Height;
const float delta = 15;
float Y = center.Y;
for (float currentRadius = maxRadius; currentRadius > 0; currentRadius -= delta) {
context.AddArc(center.X, Y, currentRadius, -ToRadians(startAngle), -ToRadians(endAngle), true);
context.StrokePath();
}
Run Code Online (Sandbox Code Playgroud)
我不在这里.如果有人能指出我正确的方向,那将是超级棒!
我想沿路径设置对象的动画.我得到了它的工作,但运动不是线性的.(它在路径中的小弯道上减速很多.)
以下是主要步骤.
1)使用PockeSVG从SVG文件导入路径
-(CGMutablePathRef)makeMutablePathFromSVG:(NSString *)svgFileName{
PocketSVG *myVectorDrawing0 = [[PocketSVG alloc] initFromSVGFileNamed:svgFileName];
UIBezierPath *myBezierPath0 = myVectorDrawing0.bezier;
return CGPathCreateMutableCopy([myBezierPath0 CGPath]);
}
Run Code Online (Sandbox Code Playgroud)
2)创建CAKeyFrameAnimation
CAKeyframeAnimation *moveAlongPath = [CAKeyframeAnimation animationWithKeyPath:@"position"];
CGMutablePathRef animationPath = CGPathCreateMutableCopy(pathForwardTo5);
[moveAlongPath setPath:animationPath];
[moveAlongPath setDuration:1.0f];
moveAlongPath.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
moveAlongPath.delegate = self;
[[trackButton layer] addAnimation:moveAlongPath forKey:@"moveButtonAlongPath"];
CFRelease(animationPath);
Run Code Online (Sandbox Code Playgroud)
我尝试使用其他CAMediaTimingFunctions,他们都表现出这种行为.
问题:动画本身有效,但它并不遵循平滑一致的速度.知道为什么吗?
我想制作一个带有三角形图标的按钮,就像iBooks app风格一样.

按下按钮时,将显示列表屏幕.然后选择一个列表,按钮的语句将是所选文本和三角形的图标.图标始终是右侧.
[self.button setImage:[UIImage imageNamed:@"arrow-down"] forState:UIControlStateNormal];
CGFloat titleWidth = self.button.titleLabel.bounds.size.width;
CGFloat imageWidth = self.button.imageView.bounds.size.width;
// Title is left Image is right
self.button.titleEdgeInsets = UIEdgeInsetsMake(0, -imageWidth, 0, imageWidth);
self.button.imageEdgeInsets = UIEdgeInsetsMake(0, titleWidth, 0, -titleWidth);
Run Code Online (Sandbox Code Playgroud)
所以我试着制作一个示例应用程序.
https://github.com/kawai-hiroyuki/LikeIBooksDropDownMenu
但是,图标的位置绝对会偏离.如何安装在右侧始终是图标.
我收到一个错误,我不明白如何解决.错误是:
Sending 'CGFloat' (aka 'float') to parameter of incompatible type 'CGFloat *' (aka 'float *');
Run Code Online (Sandbox Code Playgroud)
对于线路:
[xlabel.text drawAtPoint:CGPointMake(labelRect.origin.x, labelRect.origin.y)
forWidth:labelRect.size.width
withFont:myFont
minFontSize:5.0
actualFontSize:myFont.pointSize
lineBreakMode:UILineBreakModeWordWrap
baselineAdjustment:UIBaselineAdjustmentAlignCenters];
Run Code Online (Sandbox Code Playgroud)
错误指向actualFontSize:myFont.pointSize.myFont是一个UIFont.我这样设置:UIFont *myFont = [UIFont systemFontOfSize:17.0];
这个错误意味着什么,以及如何修复它的想法?