Tag: uiview

如何在应用程序到达前台时重新启动基于块的animation?

我有以下基于块的animation: [UIView animateWithDuration:0.5f delay:0.0f options:UIViewAnimationOptionRepeat|UIViewAnimationOptionAutoreverse|UIViewAnimationOptionAllowUserInteraction|UIViewAnimationOptionCurveEaseInOut animations:^{ [view.layer setTransform:CATransform3DMakeScale(1.3f, 1.3f, 1.0f)]; NSLog(@"animating"); }completion:^(BOOL finished){ NSLog(@"Completed"); }]; 当应用程序从后台返回时,将调用完成块,并且我的animation不会重新启动。 我试图使用下面的委托方法来重新启动animation: – (void)applicationWillEnterForeground:(UIApplication *)application { /* Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. */ [[self viewController] animate]; …… } 但是这并没有工作来恢复animation。 […]

创build自定义UIView并显示为在Swift中popup

我想创build一个自定义的UIView并使用Swift在我的主视图中popup显示它。 我的自定义UIView代码是 class DatePopUpView: UIView { var uiView:UIView? override init() { super.init() self.uiView = NSBundle.mainBundle().loadNibNamed("DatePopUpView", owner: self, options: nil)[0] as? UIView } required init(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } required override init(frame: CGRect) { super.init(frame: frame) } } 我的主要观点是: @IBAction func date_button_pressed (sender : AnyObject?) { var popUpView = DatePopUpView() var centre : CGPoint […]

屏幕左侧的UIButton(iOS 7导航幻灯片区域中)未突出显示

我有一个视图控制器(在XIB)左侧的UIButton,比如说100点宽。 如果视图控制器在常规选项卡上(即,未在导航堆栈上压入),button突出显示如预期的那样。 但是,当视图控制器位于“更多”选项卡上时(按导航堆栈上的button),左侧的button(例如最左侧的50个点)不会突出显示。 buttonfunction正在调用。 但是,当点击右侧它确实突出显示。 (顺便说一下,我认为这是一个普遍的问题,当视图控制器是从任何其他视图控制器推;可能不必是更多选项卡。 经过一番研究后发现,当我点击左侧屏幕区域时,可以将iOS-7滑回到父视图。 任何想法,为什么这是,以及如何使button再次正常工作。 谢谢你的时间!

使用IB从视图控制器的视图加载XIB自定义UIView

我有一个使用Interface Builder构build的自定义UIView ( MyCustomUIView )。 我想把这个自定义视图放在MyViewController的视图中,这也是使用IBdevise的。 我已经在MyViewController的XIB中放置了一个UIView作为子视图,并将它的类设置为MyCustomUIView 。 问题是,当我运行代码时,只有一个空白的视图出现。 (当我在代码中实例化MyCustomUIView时,它显示得很好。) 我只在MyCustomUIView.m覆盖initWithFrame:方法如下: – (id)initWithFrame:(CGRect)frame { [[NSBundle mainBundle] loadNibNamed:@"MyCustomUIView" owner:self options:nil]; self = self.view; return self; } 我该怎么做才能正确加载视图? initWithCoder:应该如何?

UIView的contentScaleFactor依赖于实现drawRect:?

我偶然发现了一件奇怪的事情。 它看起来像UIView的contentScaleFactor始终是1,即使在Retina设备,除非你实现drawRect: 考虑这个代码: @interface MyView : UIView @end @implementation MyView – (id) initWithFrame: (CGRect) frame { self = [super initWithFrame: frame]; if (self) { NSLog(@"%s %g %g %g", __PRETTY_FUNCTION__, self.contentScaleFactor, self.layer.contentsScale, [UIScreen mainScreen].scale); } return self; } – (void) didMoveToWindow { if (self.window) NSLog(@"%s %g %g %g", __PRETTY_FUNCTION__, self.contentScaleFactor, self.layer.contentsScale, [UIScreen mainScreen].scale); } @end 在Retina设备上打印下列内容: […]

从一个nib文件加载UIView没有猜测

好的,还有一个问题。 我正在创build一个名为ProgressView的UIView,它是一个具有活动指示器和进度条的半透明视图。 我希望能够在需要时在我的应用程序的不同视图控制器中使用此视图。 我知道有三种不同的方式(但我只对其中一种感兴趣): 1)以编程方式创build整个视图,根据需要进行实例化和configuration。 不用担心,我得到那一个。 2)在界面生成器中创buildUIView,添加所需的对象,并使用下面的方法加载它。 与此问题是,我们基本上猜测该视图是objectAtIndex:0,因为在文档中找不到从[[NSBundle mainBundle] loadNibName:函数返回的元素的顺序的引用。 NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:@"yournib" owner:self options:nil]; UIView *myView = [nibContents objectAtIndex:0]; myView.frame = CGRectMake(0,0,300,400); //or whatever coordinates you need [scrollview addSubview:myView]; 3)子类UIViewController,让它按照正常的方式pipe理视图。 在这种情况下,我绝对不会将视图控制器推到堆栈上,而只能看到其主视图: ProgressViewController *vc = [[ProgressViewController alloc] initWithNibName:@"ProgressView" bundle:nil]; [vc.view setCenter:CGPointMake(self.view.center.x, self.view.center.y)]; [self.view addSubview:vc.view]; [vc release]; 据我所知,#3是这样做的正确方式(除编程),但我不完全确定是否可以安全地释放ProgressView的视图控制器,而另一个控制器的视图保留其主视图(直觉说它会泄漏?)? 在这种情况下,我应该在内存pipe理方面做些什么,何时何地发布ProgressView的视图控制器? 预先感谢您的想法。 干杯, ROG

如何正确设置UIView的alpha?

我有UIView有很多子视图(UILabel,UITextView等)。 如果一个集合的alpha 0.6到主视图的所有子视图都采用这个alpha。 如何分别设置主视图的alpha?

animationUIView背景颜色迅速

我想用随机颜色为UIView的背景制作animation。 这是我迄今为止所做的: import UIKit class ViewController: UIViewController { var timer = NSTimer() var colours = UIColor() override func viewDidLoad() { super.viewDidLoad() getRandomColor() timerF() UIView.animateWithDuration(2, delay: 0.0, options:[UIViewAnimationOptions.Repeat, UIViewAnimationOptions.Autoreverse], animations: { self.view.backgroundColor = self.colours }, completion:nil) } func timerF(){ timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("getRandomColor"), userInfo: nil, repeats: true) } func getRandomColor(){ let red = […]

iPhone的iOS如何翻转/reflection任何UIView的地方?

我知道如何翻转/reflection/旋转的UIImage通过重新绘制它的范围内。 – (IBAction)reflectImageView:(UIImageView)imageView { UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, NO, 0.0); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextScaleCTM(context, 1.0, -1.0); CGContextTranslateCTM(context, 0.0, -imageView.bounds.size.height); [imageView.layer renderInContext:context]; imageView.image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); } 但是,如何为任何UIView创build一个“翻转/reflection”效果,最好是保持与之前一样的位置? 谢谢!

iPhone的iOS如何使UIRotationGestureRecognizer和UIPinchGestureRecognizer一起工作来缩放和旋转UIView子视图?

我在我的应用程序中实现了拖放/resize/旋转标签。 到目前为止,除了UIRotationGestureRecognizer手势之外,一切正在工作。 更具体地说,它不适用于UIPinchGestureRecognizer手势。 通常这两个手势竞争两个手指触摸,所以我正在并行运行它们。 以下是手势识别器调用的两种方法。 当做旋转手势时, 视图围绕它的中心旋转 ,高度和宽度变化如下:高度变成宽度,宽度变成高度。 最终,视图消失。 在视图中,我有另一个自动resize的视图。 通常,捏手势也会自动调整子视图的大小,但在这种情况下,自动调整遮罩的子视图消失。 子视图有高度和宽度的弹簧和左/顶撑杆。 我究竟做错了什么? 我怎样才能调整和扩大手势UIView? 所有委托方法和连接都正确设置。 我需要了解如何处理识别器应用缩放和旋转的顺序。 //makes 2 gesture recognizers behave together – (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{ return YES; } – (IBAction)handleRotationFrom:(id)sender { NSLog(@"Gesture rotation %.1f", rotationGestureRecognizer.rotation); //attempt to continuously rotate the label, starting with a remembered rotation float rotation = atan2(activeCompanionLabelView.transform.b, activeCompanionLabelView.transform.a); NSLog(@"existing rotation […]