- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个自定义按钮动画及其内部 View 。现在我在向按钮添加操作时遇到问题。这是代码。 LogOut
是按钮,我不知道如何在其上添加操作来注销用户。
class exampleViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.white
self.addCircleView()
// Do any additional setup after loading the view, typically from a nib.
}
func addCircleView() {
var circleView1 = VMButtonCircleFun(frame: CGRect(x: CGFloat(0), y: CGFloat(0), width: CGFloat(60), height: CGFloat(60)))
circleView1.addCircleLayer(withType: VMMakeLocation.top.rawValue)
circleView1.strokeColor = UIColor(red: 243/255, green: 106/255, blue: 106/255, alpha: 1.0)
circleView1.center = CGPoint(x: CGFloat(self.view.bounds.width / 2 - 100), y: CGFloat(self.view.bounds.height / 2))
circleView1.setIconButton(UIImage(named: "Layer 14.png")!, withType: VMMakeLocation.top.rawValue, with: UIColor(red: 127/255, green: 140/255, blue: 141/255, alpha: 1.0))
circleView1.setLineWidthValue(1.0)
self.view.addSubview(circleView1)
circleView1.buildButton()
circleView1.addTarget(self, action: #selector(self.logout), forControlEvents: .TouchUpInside)
}
func logout()
{
//TODO MAKE YOUR LOGOUT STUFFS
}
最佳答案
将VMButtonCircleFun.h和VMButtonCircleFun.m中的所有代码替换为这一段,并检查UIViewController的代码更新,
问题是您的自定义类在它自己的类上调用选择器,而不是使用自定义目标,因此我定义了一个方法来添加自定义目标(在本例中为 ViewController)并在那里调用选择器
//
// VMButtonCircleFun.h
// VMButtonCircleFun
//
// Created by Vu Mai on 6/2/15.
// Copyright (c) 2015 VuMai. All rights reserved.
//
#import <UIKit/UIKit.h>
typedef NS_ENUM(NSInteger, VMMakeLocation) {
VMMakeLocationTop = 1,
VMMakeLocationBottom
};
@interface VMButtonCircleFun : UIView
@property(nonatomic) UIColor *strokeColor;
- (void)addCircleLayerWithType:(NSInteger)type;
- (void)setStrokeEnd:(CGFloat)strokeEnd animated:(BOOL)animated;
-(void)buildButton;
-(void)setIconButton:(UIImage *)icon withType:(NSInteger)type withColor:(UIColor*)color;
-(void)setLineWidthValue:(float)lineWidthTemp;
-(void)addAction:(SEL)selector;
-(void)addTarget:(id)target;
@end
//
// VMButtonCircleFun.m
// VMButtonCircleFun
//
// Created by Vu Mai on 6/2/15.
// Copyright (c) 2015 VuMai. All rights reserved.
//
#import "VMButtonCircleFun.h"
@interface VMButtonCircleFun()
@property(nonatomic) CAShapeLayer *circleLayer;
@property (nonatomic) CAShapeLayer *lineLayerTopToBottom;
@property (nonatomic) CAShapeLayer *lineLayerBottomToHide;
@property (nonatomic, strong) UIImageView *imgIcon;
@property (nonatomic) float lineWidth;
@property (nonatomic, weak) id target;
@end
@implementation VMButtonCircleFun
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.lineWidth = 2.0f;
}
return self;
}
#pragma mark - Instance Methods
- (void)setStrokeEnd:(CGFloat)strokeEnd animated:(BOOL)animated
{
self.circleLayer.strokeEnd = strokeEnd;
}
#pragma mark - Property Setters
- (void)setStrokeColor:(UIColor *)strokeColor
{
self.circleLayer.strokeColor = strokeColor.CGColor;
self.lineLayerBottomToHide.strokeColor = strokeColor.CGColor;
self.lineLayerTopToBottom.strokeColor = strokeColor.CGColor;
_strokeColor = strokeColor;
}
-(void)setLineWidthValue:(float)lineWidthTemp
{
self.lineWidth = lineWidthTemp;
}
#pragma mark - Private Instance methods
- (void)addCircleLayerWithType:(NSInteger)type
{
CGFloat radius;
CGFloat lineWidth = self.lineWidth;
CGRect screenRect = [[UIScreen mainScreen] bounds];
// CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
CGRect rect;
UIBezierPath *path1 = [UIBezierPath bezierPath];
UIBezierPath *path2 = [UIBezierPath bezierPath];
switch (type) {
case VMMakeLocationTop:
radius = CGRectGetWidth(self.bounds)/2 - lineWidth/2;
rect = CGRectMake(lineWidth/2, lineWidth/2, radius * 2, radius * 2);
[path1 moveToPoint:CGPointMake(CGRectGetWidth(self.bounds)/2, -screenHeight)];
[path1 addLineToPoint:CGPointMake(CGRectGetWidth(self.bounds)/2, 1)];
[path2 moveToPoint:CGPointMake(CGRectGetWidth(self.bounds)/2, 1)];
[path2 addLineToPoint:CGPointMake(CGRectGetWidth(self.bounds)/2, -screenHeight)];
break;
case VMMakeLocationBottom:
radius = CGRectGetWidth(self.bounds)/2 - lineWidth/2;
rect = CGRectMake(CGRectGetWidth(self.bounds)-lineWidth/2,CGRectGetHeight(self.bounds)-lineWidth/2, radius * -2, radius * -2);
[path1 moveToPoint:CGPointMake(CGRectGetWidth(self.bounds)/2, +screenHeight)];
[path1 addLineToPoint:CGPointMake(CGRectGetWidth(self.bounds)/2, CGRectGetHeight(self.bounds)-1)];
[path2 moveToPoint:CGPointMake(CGRectGetWidth(self.bounds)/2, CGRectGetHeight(self.bounds)-1)];
[path2 addLineToPoint:CGPointMake(CGRectGetWidth(self.bounds)/2, +screenHeight)];
break;
default:
break;
}
self.circleLayer = [CAShapeLayer layer];
self.circleLayer.path = [UIBezierPath bezierPathWithRoundedRect:rect
cornerRadius:radius].CGPath;
self.circleLayer.strokeColor = self.tintColor.CGColor;
self.circleLayer.fillColor = nil;
self.circleLayer.lineWidth = lineWidth;
self.circleLayer.lineCap = kCALineCapRound;
self.circleLayer.lineJoin = kCALineJoinRound;
[self.circleLayer setStrokeEnd:0.0f];
[self.layer addSublayer:self.circleLayer];
self.lineLayerTopToBottom = [CAShapeLayer layer];
self.lineLayerTopToBottom.path = path1.CGPath;
self.lineLayerTopToBottom.lineWidth = self.lineWidth;
[self.lineLayerTopToBottom setStrokeEnd:1.0f];
self.lineLayerTopToBottom.strokeColor = [UIColor darkGrayColor].CGColor;
[self.layer addSublayer:self.lineLayerTopToBottom];\
self.lineLayerBottomToHide = [CAShapeLayer layer];
self.lineLayerBottomToHide.path = path2.CGPath;
self.lineLayerBottomToHide.lineWidth = self.lineWidth;
[self.lineLayerBottomToHide setStrokeEnd:1.0f];
self.lineLayerBottomToHide.strokeColor = [UIColor darkGrayColor].CGColor;
[self.lineLayerBottomToHide setOpacity:0];
[self.layer addSublayer:self.lineLayerBottomToHide];
[UIView setAnimationDelegate:self];
}
-(void)setIconButton:(UIImage *)icon withType:(NSInteger)type withColor:(UIColor*)color
{
self.imgIcon = [[UIImageView alloc] initWithImage:icon];
[self.imgIcon setFrame:CGRectMake(0, 0, CGRectGetWidth(self.bounds)-CGRectGetWidth(self.bounds)/2, CGRectGetHeight(self.bounds)-CGRectGetHeight(self.bounds)/2)];
self.imgIcon.image = [icon imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[self.imgIcon setContentMode:UIViewContentModeScaleAspectFit];
[self.imgIcon setTintColor:color];
switch (type) {
case VMMakeLocationTop:
[self.imgIcon setCenter:CGPointMake(CGRectGetWidth(self.bounds)/2, CGRectGetHeight(self.bounds)/2 -5 )];
break;
case VMMakeLocationBottom:
[self.imgIcon setCenter:CGPointMake(CGRectGetWidth(self.bounds)/2, CGRectGetHeight(self.bounds)/2 +5 )];
break;
default:
break;
}
[self.imgIcon setAlpha:0];
[self addSubview:self.imgIcon];
}
-(void)addAction:(SEL)selector
{
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self.target action:selector];
[self addGestureRecognizer:tap];
}
-(void)addTarget:(id)target
{
self.target = target;
}
-(void)buildButton
{
CABasicAnimation * swipeLine = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
[swipeLine setValue:@"topToBottom" forKey:@"id"];
swipeLine.delegate = self;
swipeLine.duration=1;
swipeLine.fromValue=[NSNumber numberWithDouble:0.0f];
swipeLine.toValue= [NSNumber numberWithDouble:1.0f];
swipeLine.fillMode = kCAFillModeForwards;
swipeLine.timingFunction= [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
swipeLine.removedOnCompletion=NO;
self.lineLayerTopToBottom.strokeEnd = 1.0f;
[self.lineLayerTopToBottom addAnimation:swipeLine forKey:@"topToBottom"];
}
-(void)animationLineBottomToHide
{
CABasicAnimation * swipeLine1 = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
[swipeLine1 setValue:@"bottomToHide" forKey:@"id"];
swipeLine1.duration=1;
swipeLine1.fromValue=[NSNumber numberWithDouble:1.0f];
swipeLine1.toValue= [NSNumber numberWithDouble:0.0f];
swipeLine1.fillMode = kCAFillModeForwards;
swipeLine1.timingFunction= [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
swipeLine1.removedOnCompletion=YES;
self.lineLayerBottomToHide.strokeEnd = 0.0f;
[self.lineLayerBottomToHide addAnimation:swipeLine1 forKey:@"bottomToHide"];
}
-(void)animationLineCircle
{
CABasicAnimation * swipe = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
[swipe setValue:@"drawCircle" forKey:@"id"];
swipe.duration=1;
swipe.fromValue=[NSNumber numberWithDouble:0.0f];
swipe.toValue= [NSNumber numberWithDouble:1.0f];
swipe.fillMode = kCAFillModeForwards;
swipe.timingFunction= [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
swipe.removedOnCompletion=NO;
self.circleLayer.strokeEnd = 1;
[self.circleLayer addAnimation:swipe forKey:@"drawCircle"];
[UIView animateWithDuration:0.5 delay:0.5 options:UIViewAnimationOptionCurveEaseIn animations:^{
[self.imgIcon setAlpha:1];
[self.imgIcon setCenter:CGPointMake(CGRectGetWidth(self.bounds)/2, CGRectGetHeight(self.bounds)/2)];
} completion:^(BOOL finished) {
}];
}
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
if([[anim valueForKey:@"id"] isEqual:@"topToBottom"]) {
[self.lineLayerBottomToHide setOpacity:1];
[self.lineLayerTopToBottom setOpacity:0];
[self animationLineBottomToHide];
[self animationLineCircle];
}
}
@end
<小时/>
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
var circleView1 = VMButtonCircleFun(frame: CGRect(x: CGFloat(0), y: CGFloat(0), width: CGFloat(60), height: CGFloat(60)))
circleView1.addCircleLayer(withType: VMMakeLocation.top.rawValue)
circleView1.strokeColor = UIColor(red: 243/255, green: 106/255, blue: 106/255, alpha: 1.0)
circleView1.center = CGPoint(x: CGFloat(self.view.bounds.width / 2 - 100), y: CGFloat(self.view.bounds.height / 2))
//circleView1.setIconButton(UIImage(named: "Layer 14.png")!, withType: VMMakeLocation.top.rawValue, with: UIColor(red: 127/255, green: 140/255, blue: 141/255, alpha: 1.0))
circleView1.setLineWidthValue(1.0)
self.view.addSubview(circleView1)
circleView1.buildButton()
circleView1.addTarget(self)
circleView1.addAction(#selector(self.logout))
}
func logout()
{
debugPrint("LOGOUT")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
我希望这对你有帮助,现在就像魅力一样
关于ios - 向自定义按钮添加操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41351668/
我创建了一个用户可以添加测试的字段。这一切运行顺利我只希望当用户点击(添加另一个测试)然后上一个(添加另一个测试)删除并且这个显示在新字段中。 所有运行良好的唯一问题是点击(添加另一个字段)之前添加另
String[] option = {"Adlawan", "Angeles", "Arreza", "Benenoso", "Bermas", "Brebant
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我正在努力将 jQuery 滚动功能添加到 nav-tab (Bootstrap 3)。我希望用户能够选择他们想要的选项卡,并在选项卡内容中有一个可以平滑滚动到 anchor 的链接。这是我的代码,可
我正在尝试在用户登录后再添加 2 个 ui 选项卡。首先,我尝试做一个之后。 $('#slideshow').tabs('remove', '4'); $("#slideshow ul li:last
我有一个包含选择元素的表单,我想通过选择添加和删除其中一些元素。这是html代码(这里也有jsfiddle http://jsfiddle.net/txhajy2w/):
正在写这个: view.backgroundColor = UIColor.white.withAlphaComponent(0.9) 等同于: view.backgroundColor = UICo
好的,如果其中有任何信息,我想将这些列添加到一起。所以说我有 账户 1 2 3 . 有 4 个帐户空间,但只有 3 个帐户。我如何创建 java 脚本来添加它。 最佳答案 Live Example H
我想知道是否有一种有效的预制算法来确定一组数字的和/差是否可以等于不同的数字。示例: 5、8、10、2,使用 + 或 - 等于 9。5 - 8 = -3 + 10 = 7 + 2 = 9 如果有一个预
我似乎有一个卡住的 git repo。它卡在所有基本的添加、提交命令上,git push 返回所有内容为最新的。 从其他帖子我已经完成了 git gc 和 git fsck/ 我认为基本的调试步骤是
我的 Oracle SQL 查询如下- Q1- select hca.account_number, hca.attribute3, SUM(rcl.extended_amou
我正在阅读 http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingG
我正在尝试添加一个“加载更多”按钮并限制下面的结果,这样投资组合页面中就不会同时加载 1000 个内容,如下所示:http://typesetdesign.com/portfolio/ 我对 PHP
我遇到这个问题,我添加了 8 个文本框,它工作正常,但是当我添加更多文本框(如 16 个文本框)时,它不会添加最后一个文本框。有人遇到过这个问题吗?提前致谢。 Live Link: JAVASCRIP
add/remove clone first row default not delete 添加/删除克隆第一行默认不删除&并获取正确的SrNo(例如:添加3行并在看到问题后删除SrNo.2)
我编码this ,但删除按钮不起作用。我在控制台中没有任何错误.. var counter = 0; var dataList = document.getElementById('materi
我有一个类似数组的对象: [1:数组[10]、2:数组[2]、3:数组[2]、4:数组[2]、5:数组[3]、6:数组[1]] 我正在尝试删除前两个元素,执行一些操作,然后将它们再次插入到同一位置。
使用的 Delphi 版本:2007 你好, 我有一个 Tecord 数组 TInfo = Record Name : String; Price : Integer; end; var Info
我使用了基本的 gridster 代码,然后我声明了通过按钮添加和删除小部件的函数它工作正常但是当我将调整大小功能添加到上面的代码中时,它都不起作用(我的意思是调整大小,添加和删除小部件) 我的js代
title 323 323 323 title 323 323 323 title 323 323 323 JS $(document).keydown(function(e){
我是一名优秀的程序员,十分优秀!