我试图将添加UIRefreshControl
到UICollectionView
,但问题是,刷新控制不会出现,除非集合视图填补了其父容器的高度.换句话说,除非集合视图足够长以至于需要滚动,否则无法向下拉以显示刷新控件视图.一旦集合超过其父容器的高度,它就会被拉下并显示刷新视图.
我已经UICollectionView
在主视图内部设置了一个快速iOS项目,并在集合视图中添加了一个插座,以便我可以添加UIRefreshControl
它viewDidLoad
.还有一个带有重用标识符的原型单元cCell
这是控制器中的所有代码,它很好地演示了这个问题.在此代码中,我将单元格的高度设置为100,这不足以填充显示,因此无法拉取视图并且不会显示刷新控件.将其设置为更高的值以填充显示,然后它可以工作.有任何想法吗?
@interface ViewController () <UICollectionViewDelegateFlowLayout, UICollectionViewDataSource>
@property (strong, nonatomic) IBOutlet UICollectionView *collectionView;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[self.collectionView addSubview:refreshControl];
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 1;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
return [collectionView dequeueReusableCellWithReuseIdentifier:@"cCell" forIndexPath:indexPath];
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake(self.view.frame.size.width, 100);
}
Run Code Online (Sandbox Code Playgroud) 使用ui-router
,可以将一个$state
或两个$stateParams
注入控制器以访问URL中的参数.但是,通过$stateParams
仅公开属于由访问它的控制器管理的状态的参数及其父状态来访问$state.params
参数,同时具有所有参数,包括处于任何子状态的参数.
给定以下代码,如果我们直接加载URL http://path/1/paramA/paramB
,这是控制器加载时的方式:
$stateProvider.state('a', {
url: 'path/:id/:anotherParam/',
controller: 'ACtrl',
});
$stateProvider.state('a.b', {
url: '/:yetAnotherParam',
controller: 'ABCtrl',
});
module.controller('ACtrl', function($stateParams, $state) {
$state.params; // has id, anotherParam, and yetAnotherParam
$stateParams; // has id and anotherParam
}
module.controller('ABCtrl', function($stateParams, $state) {
$state.params; // has id, anotherParam, and yetAnotherParam
$stateParams; // has id, anotherParam, and yetAnotherParam
}
Run Code Online (Sandbox Code Playgroud)
问题是,为什么差异?是否有关于何时以及为何使用或避免使用其中任何一种的最佳实践指南?
对于TypeScript 1.7中的Polymorphic,我在这里发现,我们可以在类中定义一个返回类型为的方法this
,并自动地,任何扩展该类并继承方法的类,将其返回类型设置为各自的this
类型.像这样:
class Model {
save():this { // return type: Model
// save the current instance and return it
}
}
class SomeModel extends Model {
// inherits the save() method - return type: SomeModel
}
Run Code Online (Sandbox Code Playgroud)
但是,我所追求的是拥有一个static
带有返回类型的继承方法,引用类本身.最好用代码描述:
class Model {
static getAll():Model[] {
// return all recorded instances of Model as an array
}
save():this {
// save the current instance and return it
}
}
class SomeModel extends Model …
Run Code Online (Sandbox Code Playgroud) 我原本以为这将是一项非常简单的任务,但我现在已经苦苦挣扎了几天,而且有点沮丧!我对Windows批处理脚本不是很熟悉,所以如果你知道答案,请尽量保持简单:)
基本上,我有一个Windows关闭脚本(.bat文件),我想知道两个文本文件是否相同(即它们的内容完全相同),如果是这样,执行goto命令(例如goto line10)
我无法弄清楚如何做到这一点!非常感谢您的帮助!
有没有办法使用Angular的DI将依赖项注入装饰器工厂?我们将以下代码作为简化示例:
@Component({
selector: 'hello-component',
template: '<div>Hello World</div>'
})
export class HelloComponent {
@PersonName()
name: string;
ngAfterViewInit() {
console.log(`Hello, ${this.name}`);
}
}
Run Code Online (Sandbox Code Playgroud)
这里,PersonName
装饰器的预期行为是它访问Person
依赖项,并使用它来设置name
类的属性.
是否有可能PersonName
为上面的代码实现装饰器?
我正在使用CarrierWave::RMagick
为Rails应用程序创建图像的缩略图版本,并且我注意到图像缩小时的质量损失.这在一定程度上是可以理解的,因为我们在缩小图像中的像素较少,因此质量较差,但我希望质量更好.我给你举个例子:
从左到右,第一个是原始(100x105),第二个是Photoshop的Bicubic调整大小(95x100),第三个是RMagick resize_to_fit
(95x100)的结果.
对于此示例,原始图像仅略大于我想要的缩略图,但我基本上强制每个缩略图最大为100x100.我希望你能看到缩小尺寸的图像之间的区别.将Photoshop的质量与RMagick的质量进行比较可能是愚蠢的,但即使在Chrome中缩小以使图像更小也能产生更高质量的图像.
我基本上在CarrierWave上传器类中使用它:
version :thumb do
process :resize_to_fit => [100, 100]
end
Run Code Online (Sandbox Code Playgroud)
关于如何改善图像质量的任何想法?或者,如果有任何替代RMagick可以做得更好?
编辑:我试过这个,虽然没有任何区别.无论如何,我认为那是JPEG图像.
ruby-on-rails rmagick thumbnails image-uploading carrierwave
我有一个ASP.NET网站,我正在尝试将一些Angular 2内容合并到其中.网站上有各种页面,有很多静态内容.在某些页面上,我需要渲染一些呈现为Angular 2应用程序的动态内容.
/* CSS not important */ body { font-family: sans-serif; padding: 5px; } [data-dynamic-app] { color: white; padding: 8px; background: #4444ff; margin: 10px 0; }
Run Code Online (Sandbox Code Playgroud)
<section>
<h2>Some Static Content</h2>
<p>
There is static content on the page that is rendered by the ASP.NET application.
</p>
</section>
<div data-dynamic-app="appA">Placeholder for App A</div>
<div data-dynamic-app="appB">Placeholder for App B</div>
Run Code Online (Sandbox Code Playgroud)
这在客户端是没有问题的,因为我已经设法迭代我的占位符元素(由data-dynamic-app
它们上的属性标识),并为每个元素引导相应的Angular应用程序.十分简单.
但是,出于SEO的原因,我需要添加服务器端渲染,以便在页面的Angular部分到达客户端代码之前进行渲染.我面临的挑战是,我正在尝试将其构建为通过IIS提供的ASP.NET网站的现有Visual Studio解决方案,我不知道如何去做.
我一直在脑子里运行想法,但作为一个没有Angular Universal先前经验的前端开发人员,我无法确定哪些想法很简单,哪些可能实际上让我在某处.以下是我想到的一些事情:
以上可能或根本没有任何意义,我不知道它们的"如果"或"如何".我基本上不熟悉ASP.NET,IIS甚至Angular Universal.因此,任何澄清/改进上述或完全不同和更好的想法的想法都将受到高度赞赏.
是否可以更改接口中声明的属性的类型?我不知道如何用文字解释这个,所以这里有一个简化的例子,说明我正在尝试做的事情是行不通的:
假设Movie
命名空间是在我无法控制的第三方库中定义的:
declare namespace Movie {
interface Character {
doSomething(): Promise<void>;
friend: Character;
}
}
Run Code Online (Sandbox Code Playgroud)
现在在我的应用程序中,我希望我的角色成为Super,与超级朋友.所以我试着用我自己的打字方式做到这一点:
declare namespace Movie {
interface Character {
doAnExtraThing(): Promise<void>; // OK to add a new method
nickname: string; // OK to add a new property
friend: SuperCharacter; // NOT OK to override type with a subtype
}
interface SuperCharacter extends Character {
doSomethingSuper(): Promise<void>;
}
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用,因为TypeScript不允许我覆盖friend
属性类型SuperCharacter
,即使定义a SuperCharacter
是 a Character
.TypeScript抱怨此错误:
[ts] Subsequent variable declarations must have …
Run Code Online (Sandbox Code Playgroud) 我遇到了问题[UICollectionView reloadData]
,在调用numberOfSectionsInCollectionView
我指定的委托之前,它似乎已经停滞了很长一段时间.这是发生的事情:
应用程序以立即可见的UICollectionView开始,并numberOfSectionsInCollectionView
在委托上调用,该委托返回空数组中的项目数(即0),并立即开始从Web服务下载数组的数据.下载完成后,数据被反序列化并添加到上面的数组中,然后reloadData
在UICollectionView
实例上调用.这是应用程序似乎停止做任何事情的地方,并在20-30秒(或有时长达一分钟)后,代表接到一个电话numberOfSectionsInCollectionView
.收到此调用后,重新加载很快就会完成.
我相信reloadData
在自己的线程中运行,但我尝试在一个单独的线程中启动它,以确保它不是我的任何代码阻止进程.什么可能reloadData
在它看起来卡住时做?有没有之间的任何中介委托方法reloadData
和numberOfSectionsInCollectionView
我应该执行?我认为这是第一个在重新加载后调用的方法,就iOS开发人员而言.
如果有人能告诉我可能出错的地方,太棒了,但我也很感激有关如何调试这个的提示!
在NativeScript中为UI插件定义自定义事件需要什么?
我想要实现的是触发一个foo
与a上的事件类似的tap
事件,Button
并且可以挂钩如下:
<Page xmlns="http://schemas.nativescript.org/tns.xsd"
xmlns:fooplugin="nativescript-foo-plugin">
<StackLayout>
<Button text="Tap Me!" tap="{{ onTap }}" />
<fooplugin:FooPlugin foo="{{ onFoo }}" />
</StackLayout>
</Page>
Run Code Online (Sandbox Code Playgroud)
我所做的基本上归结为在插件代码中使用from 值调用notify
函数(忽略内存泄漏注意事项):eventName
foo
import * as view from 'ui/core/view';
export class FooPlugin extends view.View {
constructor() {
super();
setTimeout(() => {
this.notify({
eventName: 'foo',
object: this,
});
// also tried this._emit('foo');
}, 1000);
}
}
Run Code Online (Sandbox Code Playgroud)
还有其他我缺少的东西,我需要做些什么来使这项工作?
免责声明:我发现很难在问题标题中概括问题,所以如果您有更好的建议,请在评论中告诉我。
让我们看一下以下简化的 TypeScript 类:
class Model {
save():Model {
// save the current instance and return it
}
}
Run Code Online (Sandbox Code Playgroud)
该类Model
有一个save()
返回自身实例的方法: a Model
。
我们可以Model
这样扩展:
class SomeModel extends Model {
// inherits the save() method
}
Run Code Online (Sandbox Code Playgroud)
因此,SomeModel
将继承save()
,但它仍然返回 a Model
,而不是 a SomeModel
。
有没有一种方法,也许使用泛型,将save()
in的返回类型设置SomeModel
为SomeModel
,而不必在继承类内部重新定义它?
typescript ×4
angular ×2
generics ×2
inheritance ×2
ios ×2
static ×2
angularjs ×1
asp.net ×1
batch-file ×1
carrierwave ×1
compare ×1
decorator ×1
file ×1
iis ×1
nativescript ×1
plugins ×1
reloaddata ×1
rmagick ×1
thumbnails ×1
types ×1
windows ×1