我对使用Xcode开发iOS应用程序感到有点好奇,尽管我们特别指出:
#import <QuartzCore/QuartzCore.h>
Run Code Online (Sandbox Code Playgroud)
在我们ViewController.h的项目链接时,QuartzCore库不会自动链接.这是为什么?
我正在尝试构建一个动画圆圈,它将顺时针绘制,直到它变成完整的圆圈,如iPhone核心动画 - 绘制圆圈所示
问题是CALayer没有添加或构建对象.我测试过并发现它没有访问我drawInContext:CGContextRef和animatingArc方法.
到目前为止我所做的是:
在AnimateArc.h中
@interface AnimateArc : CALayer {
CAShapeLayer *circle;
}
-(void) animatingArc;
@end
Run Code Online (Sandbox Code Playgroud)
在AnimateArc.m中
-(void) drawInContext:(CGContextRef)ctx
{
CGFloat radius = 50.0;
circle = [CAShapeLayer layer];
//make a circular shape
circle.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0.0, 0.0, 2 * radius, 2 * radius) cornerRadius:radius].CGPath;
CGPoint centerPoint = CGPointMake(CGRectGetWidth(self.bounds)/2, CGRectGetHeight(self.bounds)/2);
//center the shape in self.view
circle.position = centerPoint;
//configure appearence of circle
circle.fillColor = [UIColor clearColor].CGColor;
circle.strokeColor = [UIColor blackColor].CGColor;
circle.lineWidth = 5; …Run Code Online (Sandbox Code Playgroud) 我有一个UITableView透明的backgroundColor,里面的单元格用以下代码初始化
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.label = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, CGRectGetWidth(self.contentView.frame), 180)];
self.label.autoresizingMask = UIViewAutoresizingFlexibleWidth;
self.label.text = @"test";
[self.contentView addSubview:self.label];
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
每行的高度为200,标签不会填满整个单元格.每个单元格之间将有透明部分.当我尝试通过触摸那些透明部分来滚动表格时,触摸完全被忽略.我知道,从iOS5开始,对视图的触摸将被忽略.我该怎么做才能解决这个问题?
我尝试过的东西不起作用:
设置透明或隐藏或alpha = 0 UIView作为tableView的假背景
相同的交易,触摸被忽略.
UIView在tableView上创建子类,子类UIView使用tableView作为nextResponder
显然UITableView不使用touchesBegan/cancelled/ends/moved,所以这不起作用.我不认为实现我的滚动方法是明智的UITableView.
将tableView的backgroundColor设置为 [UIColor colorWithRed:0 green:0 blue:0 alpha:0.1]
我不想这样做,它仍然可见.
简而言之,即使我从透明部分开始滚动,我还能做什么来滚动表?
我想在不旋转UIView本身的情况下围绕中心点旋转UIView.所以更像是摩天轮的车(总是保持直立),而不是钟表的手.
我围绕中心点旋转UIViews的时间,我使用了图层位置/ anchorPoint /变换来完成效果.但这显然会改变视图本身的方向.
有帮助吗?
凯勒
我将Text归为不同的文本颜色.为了更好地阅读突出显示的文本,我使用backgroundcolor.是否有可能在这个Textarea上带来圆角的CALayer效果?不是整个区域,而是内部的特殊文本.
我的代码:
NSAttributedString *text = [[NSAttributedString alloc] initWithString:@"Highlighted Text"
attributes:@{
NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue" size:10.0f],
NSForegroundColorAttributeName: [UIColor lightGrayColor],
NSBackgroundColorAttributeName: [UIColor darkGrayColor]
}];
Run Code Online (Sandbox Code Playgroud) 我再次接近,但没有香蕉.
我正在尝试按照面部识别的一些教程.几乎有以下代码,但我认为有些东西我不知道它是如何缩放和在UIImageView边缘周围放置边框.
我在照片库中的照片大小不一(出于某种莫名其妙的原因),所以我想象的CIDetector是找到面孔,我正在应用CGAffineTransforms等等,并试图将它们放入UIImageView.但是,正如您从图像(也在下面)中看到的那样,它并没有被绘制到正确的位置.
它UIImageView是280x500并设置为Scale to Fill.
任何有助于解决正在发生的事情的帮助都会很棒!
-(void)detectFaces {
CIContext *context = [CIContext contextWithOptions:nil];
CIImage *image = [CIImage imageWithCGImage:_imagePhotoChosen.image.CGImage options:nil];
CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeFace context:context options:@{CIDetectorAccuracy : CIDetectorAccuracyHigh}];
CGAffineTransform transform = CGAffineTransformMakeScale(1, -1);
transform = CGAffineTransformTranslate(transform, 0, -_imagePhotoChosen.image.size.height);
NSArray *features = [detector featuresInImage:image];
NSLog(@"I have found %lu faces", (long unsigned)features.count);
for (CIFaceFeature *faceFeature in features)
{
const CGRect faceRect = CGRectApplyAffineTransform(faceFeature.bounds, transform);
NSLog(@"I have the original frame as: %@", …Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个使用图层的应用程序,我的应用程序结构是
UIView --> UIScrollView --> UIView --> LayersView (Custom UIView)
--> UIImageView
Run Code Online (Sandbox Code Playgroud)
我想多层添加到LayersView,所以我建立一个自定义CALayer使用UIBezierPath绘制一组点.
CALayerBezierPath.h
#import <QuartzCore/QuartzCore.h>
@interface CALayerBezierPath : CALayer {
NSMutableArray *pointsArray;
}
@property (nonatomic, retain) NSMutableArray *pointsArray;
- (void) initVariables;
- (void) addNewPoints:(CGPoint)newPoint;
@end
Run Code Online (Sandbox Code Playgroud)
CALayerBezierPath.m
#import "CALayerBezierPath.h"
@implementation CALayerBezierPath
@dynamic pointsArray;
-(void)drawInContext:(CGContextRef)ctx {
NSLog(@"CALayerBezierPath - drawInContext");
if ([pointsArray count] > 0) {
UIColor *color = [UIColor redColor];
[color set];
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:[[pointsArray objectAtIndex:0] CGPointValue]];
for (int x = 1; x …Run Code Online (Sandbox Code Playgroud) 我有一个游戏,用户可以创建自定义级别并上传到我的服务器供其他用户玩,我想在用户测试他/她的级别上传到我的服务器之前获取"操作区域"的屏幕截图一个"预览图像".
我知道如何获取整个视图的屏幕截图,但我想将其定义为自定义框架.请考虑以下图像:

我想用红色区域截取屏幕截图,即"动作区域".我能做到吗?
我这里有一个相当简单的问题.基本上我正在尝试将一个对象(一个UIImageView)从A点(它在故事板中设置)移动到我以编程方式定义的B点.
我的第一次传递导致了这段代码
UIView.animateWithDuration(0.75, delay: 0.5, options: UIViewAnimationOptions.CurveLinear, animations: {
self.signInButton.alpha = 1
self.signInButton.center.y = 10
}, completion: nil)
Run Code Online (Sandbox Code Playgroud)
但是,此代码的作用基本上是将按钮偏离中心,然后再返回其原始位置.
然后我调查了QuartzCore来帮助我,但一切都在Objective-C中.我有这个方法:
func moveImage(view: UIImageView){
var toPoint: CGPoint = CGPointMake(0.0, -10.0)
var fromPoint : CGPoint = CGPointZero
var movement = CABasicAnimation(keyPath: "movement")
movement.additive = true
movement.fromValue = fromPoint
movement.toValue = toPoint
movement.duration = 0.3
view.layer.addAnimation(movement, forKey: "move")
}
Run Code Online (Sandbox Code Playgroud)
但是这里的问题是movement.fromValue不能接受的CGPoint.我知道在目标C中有一个函数将a转换CGPoint为a NSValue,但是这个函数似乎是从Swift中弃用的,我找不到另一种方法.
因此,我的问题是,如何转换CGPoint为NSValue使我的moveImage()功能工作,还是有更好的方法将对象从A点移动到B点?
谢谢!
我想创建一个类似于动画的动画,用于在Spy Mouse应用程序中更改不同视图之间的动画.观看此视频以供参考:
http://www.youtube.com/watch?v=ylFdl7W3Srw

我不能这样做.我的动画显示的是矩形区域而不是圆形视图.
CABasicAnimation *cornerRadiusAction = [CABasicAnimation animationWithKeyPath:@"cornerRadius"];
cornerRadiusAction.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
cornerRadiusAction.duration = 5.0f;
cornerRadiusAction.toValue = [NSNumber numberWithFloat:self.view.bounds.size.height*2];
[self.view.layer addAnimation:cornerRadiusAction forKey:nil];
Run Code Online (Sandbox Code Playgroud) quartz-core ×10
ios ×7
objective-c ×4
iphone ×2
uiimageview ×2
calayer ×1
cgcontext ×1
core-image ×1
invisible ×1
ios4 ×1
ios5 ×1
ios8 ×1
screenshot ×1
swift ×1
uilabel ×1
uitableview ×1
uiview ×1
xcode ×1