我有一个UITableViewController,如果满足某些条件,将显示表视图标题(NOT节标题).在加载时显示带或不带标题视图的控制器都可以正常工作.但是如果我显示标题,然后将其删除,则每次都会将间距(标题框的位置)保留在表格视图的顶部.
我在删除表视图标题时没有运气,尝试了以下各种组合:
[self.tableView beginUpdates];
self.tableView.tableHeaderView = nil;
self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectZero];
[self.tableView reloadData];
[self.tableView endUpdates];
Run Code Online (Sandbox Code Playgroud)
还有其他人遇到过吗?
表视图标题代码:
- (void)updateTableHeaderView
{
if (self.alerts.count && self.isViewLoaded) {
[self.tableView beginUpdates];
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, CGRectGetWidth(self.tableView.bounds), 40.0f)];
headerView.preservesSuperviewLayoutMargins = YES;
self.tableView.tableHeaderView = headerView;
UIButton *alertButton = [UIButton buttonWithType:UIButtonTypeCustom];
alertButton.tintColor = [UIColor whiteColor];
alertButton.translatesAutoresizingMaskIntoConstraints = NO;
[alertButton setBackgroundImage:[UIImage imageWithColor:alertTintColor] forState:UIControlStateNormal];
[alertButton setBackgroundImage:[UIImage imageWithColor:alertHighlightedTintColor] forState:UIControlStateHighlighted];
[alertButton addTarget:self action:@selector(alertButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[headerView addSubview:alertButton];
NSDictionary *views = NSDictionaryOfVariableBindings(alertButton);
NSDictionary *metrics = nil;
[NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|[alertButton]|" …
Run Code Online (Sandbox Code Playgroud) 尝试添加使用FTP以及该文件夹中包含的所有子文件夹和文件删除文件夹的功能。
我已经建立了一个递归函数来做到这一点,我觉得逻辑是正确的,但仍然行不通。
我做了一些测试,如果路径只是一个空文件夹或一个文件,我可以在第一次运行时删除,但是如果它是一个包含一个文件的文件夹或一个包含一个空子文件夹的文件夹,则无法删除。因此遍历文件夹并使用该函数删除似乎是一个问题。
有任何想法吗?
function ftpDelete($directory)
{
if(empty($directory))//Validate that a directory was sent, otherwise will delete ALL files/folders
return json_encode(false);
else{
global $conn_id;
# here we attempt to delete the file/directory
if( !(@ftp_rmdir($conn_id,$directory) || @ftp_delete($conn_id,$directory)) )
{
# if the attempt to delete fails, get the file listing
$filelist = @ftp_nlist($conn_id, $directory);
# loop through the file list and recursively delete the FILE in the list
foreach($filelist as $file)
ftpDelete($file);
#if the file list is empty, delete the DIRECTORY we …
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个逼真的bobblehead应用程序,并希望使用物理学来挖掘动画.我已经看到其他应用程序在那里做,并从我收集我需要使用SpriteKit.
我创建了一个SKScene,并使用SKPhysicsJointPin将头部固定在身体上,但它根本不会移动.任何想法或建议?
更新后的代码(5/28):
现在在头上使用2个弹簧接头,它从左向右移动,但不是向上和向下移动.此外,快速敲击会使头部最终足够远,直至"跌落"并且不在视线范围内.奇怪的.
对于适当的设置有什么想法,让它能够在它的起始位置远离中心并保持在指定区域内,以便它能够从身体上滑落并看起来很有趣?
BobbleheadView是一个子类SKView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.backgroundColor =[UIColor clearColor];
self.showsFPS = YES;
self.showsNodeCount = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(animateBobble)];
[self addGestureRecognizer:tap];
SKScene *bobbleheadScene = [SKScene sceneWithSize:self.bounds.size];
[self presentScene:bobbleheadScene];
// 1. Body
self.body = [SKSpriteNode spriteNodeWithImageNamed:@"Bobble-Body"];
self.body.position = CGPointMake(self.frame.size.width/2, self.body.frame.size.height/2);
self.body.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame];
[bobbleheadScene addChild:self.body];
// 2. Head
self.head = [SKSpriteNode spriteNodeWithImageNamed:@"Bobble-Head"];
self.head.position = CGPointMake(self.center.x, self.body.frame.size.height);
//self.head.physicsBody.affectedByGravity = YES;
// self.head.physicsBody.dynamic = NO;
//This …
Run Code Online (Sandbox Code Playgroud) 我正在为通知下拉列表创建一个UIView子类.我正在使用XIB构建视图,并希望在初始化时将该xib分配给类(即避免必须从调用ViewController执行此操作).
由于你无法在swift中分配给'self',我如何从类本身中正确地执行此操作?
class MyDropDown: UIView
{
func showNotification()
{
self = UINib(nibName: nibNamed, bundle: bundle).instantiateWithOwner(nil, options: nil)[0] as? UIView
}
}
Run Code Online (Sandbox Code Playgroud) 我正在从服务器下载一堆图像文件,我想确保只有在它们更新时才下载它们.此方法目前正好下载图像.但是,每次用户登录应用程序时,我都不想浪费时间或精力重新下载图像.相反,我只想下载A)不存在的任何文件B)服务器上的文件比设备上的文件更新
以下是我下载图像的方式:*图像网址与其关联的视频保存在Core Data中.使用我构建的简单转换方法生成url(generateThumbnailURL)
-(void)saveThumbnails{
NSManagedObjectContext *context = [self managedObjectContextThumbnails];
NSError *error;
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"Videos" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
NSLog(@"Videos: %i",fetchedObjects.count);
if (fetchedObjects.count!=0) {
for(Videos *currentVideo in fetchedObjects){
// Get an image from the URL below
NSURL *thumbnailURL = [self generateThumbnailURL:[currentVideo.videoID intValue]];
UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:thumbnailURL]];
// Let's save the file into Document folder.
// You can also change this to your desktop for testing. …
Run Code Online (Sandbox Code Playgroud) 我试图动画a的图像UIButton
.动画运行正常,但之后它总是在按钮上添加灰色(就像它被突出显示/选中一样).
码:
NSArray *images = [[NSArray alloc] init];
images = [NSArray arrayWithObjects:
[UIImage imageNamed:IMAGE1],
[UIImage imageNamed:IMAGE2],
[UIImage imageNamed:IMAGE3],
[UIImage imageNamed:IMAGE4],
nil];
iconBobble.imageView.animationImages = images;
iconBobble.imageView.animationDuration = 1.5;
iconBobble.imageView.animationRepeatCount = 1;
[iconBobble.imageView startAnimating];
Run Code Online (Sandbox Code Playgroud) 我正在快速编写一个应用程序,并使用单例在整个应用程序中共享一个类对象 User。我希望能够在用户注销时将此单例设置为“nil”,以便当他们重新登录时,旧属性不再存在(即名称、用户名等)。我希望有一种简单的方法可以将单例设置回 nil,而不必将每个属性设置为 nil。
这是我在应用程序中用作User.activeUser 的User 类:
class User: NSObject
{
class var activeUser : User? {
struct Static {
static let instance : User = User()
}
return Static.instance
}
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能改变这一点,以便下面的代码不会给我一个警告,并且实际上消除了单例对象:
User.activeUser = nil
Run Code Online (Sandbox Code Playgroud) 我正在尝试在 ARKit 的语音气泡中创建一个带有简单文本的报价生成器。
我可以用文本显示语音气泡,但文本始终从中间开始并溢出到语音气泡之外。
任何帮助让它在语音气泡的左上角对齐并包裹在语音气泡内的帮助将不胜感激。
结果
课程
class SpeechBubbleNode: SCNNode {
private let textNode = TextNode()
var string: String? {
didSet {
textNode.string = string
}
}
override init() {
super.init()
// Speech Bubble
let plane = SCNPlane(width: 200.0, height: 100.0)
plane.cornerRadius = 4.0
plane.firstMaterial?.isDoubleSided = true
geometry = plane
// Text Node
textNode.position = SCNVector3(position.x, position.y, position.z + 1.0)
// textNode.position = convertPosition(SCNVector3(0.0, 0.0, 1.0), to: textNode)
// textNode.position = SCNVector3(0.0, 0.0, position.z + 1.0)
addChildNode(textNode)
}
required init?(coder …
Run Code Online (Sandbox Code Playgroud) 我正在构建一个自定义进度条(UIView的子类).我向UIView添加了一个UIImageView,它使用重复的图像来显示进度.视图被添加到故事板中,我可以让它显示得很好,但是如果我尝试更改框架,那么它只显示故事板文件中显示的内容(即,如果故事板视图具有黄色背景,但代码uiview子类将其更改为绿色,如果我尝试在代码中更改UIImageView的框架以反映当前进度,则默认返回黄色背景)
我尝试使用这些没有运气:
[self updateConstraints];
[self layoutSubviews];
Run Code Online (Sandbox Code Playgroud)
UPDATE
我知道我需要设置一个约束用于autolayout.但是,它需要以编程方式完成,因为我正在以这种方式创建子类UIView.这是我正在尝试的代码,我知道我很接近,但不能让它工作:
[self addConstraint:
[NSLayoutConstraint constraintWithItem:self.progressView
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationLessThanOrEqual
toItem:nil
attribute:NSLayoutAttributeWidth
multiplier:1
constant:progressWidth]];
[UIView animateWithDuration:3 animations:^{
[self.progressView layoutIfNeeded];
}];
Run Code Online (Sandbox Code Playgroud) 我试图通过检索每个产品标识符的NSUserDefaults值来查看用户是否已进行购买.我在购买产品时保存了该值并且设置正确.
调用时,键值对正确显示:
NSLog(@"%@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);
Run Code Online (Sandbox Code Playgroud)
这样:
"com.COMPANY.PRODUCTIDENTIFIER" = 1;
Run Code Online (Sandbox Code Playgroud)
但是当我尝试实际验证特定的键值时,它总是返回null:
for (NSString * productIdentifier in _productIdentifiers) {
NSLog(@"ProductIdentifier: %@",productIdentifier);
NSLog(@"Defaults Value: %@",[[NSUserDefaults standardUserDefaults] valueForKey:productIdentifier]);
NSLog(@"Defaults Bool: %d",[[NSUserDefaults standardUserDefaults] boolForKey:productIdentifier]);
NSLog(@"Defaults Object: %@",[[NSUserDefaults standardUserDefaults] objectForKey:productIdentifier]);
BOOL productPurchased = [[NSUserDefaults standardUserDefaults] boolForKey:productIdentifier];
if (productPurchased) {
[_purchasedProductIdentifiers addObject:productIdentifier];
NSLog(@"Previously purchased: %@", productIdentifier);
} else {
NSLog(@"Not purchased: %@", productIdentifier);
}
}
Run Code Online (Sandbox Code Playgroud)
结果如下:
2013-03-10 17:45:13.609 COMPANY[1140:907] ProductIdentifier: com.COMPANY.PRODUCTIDENTIFIER
2013-03-10 17:45:13.611 COMPANY[1140:907] Defaults Value: (null)
2013-03-10 17:45:13.612 COMPANY[1140:907] Defaults Bool: 0
2013-03-10 17:45:13.611 COMPANY[1140:907] …
Run Code Online (Sandbox Code Playgroud) ios ×8
animation ×2
null ×2
swift ×2
arkit ×1
download ×1
frame ×1
ftp ×1
image ×1
init ×1
nsdata ×1
nsurl ×1
objective-c ×1
php ×1
physics ×1
rmdir ×1
scnnode ×1
scntext ×1
singleton ×1
spacing ×1
sprite-kit ×1
storyboard ×1
subclass ×1
subview ×1
tableheader ×1
uiimage ×1
uitableview ×1
uiview ×1
word-wrap ×1
xib ×1